diff --git a/.travis.yml b/.travis.yml index 9cf434d..9f9c5c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ # Travis configuration -dist: 'trusty' +dist: 'xenial' sudo: 'required' services: diff --git a/meta/main.yml b/meta/main.yml index 34dfbbe..9c26f84 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -20,5 +20,5 @@ galaxy_info: - 'system' dependencies: - src: 'Temelio.ssmtp' - version: '0.1.0' + version: '0.1.1' when: 'ssmtp_use_ansible_galaxy_dependencies or _use_role_dependencies' diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml index a50445d..ec44814 100644 --- a/molecule/default/requirements.yml +++ b/molecule/default/requirements.yml @@ -1,4 +1,4 @@ --- - src: 'Temelio.ssmtp' - version: '0.1.0' + version: '0.1.1' diff --git a/requirements.txt b/requirements.txt index 4cccad0..4648dc5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -docker==4.0.1 -molecule==2.20.1 +docker==4.0.2 +molecule==2.20.2 pytest==4.5.0 six==1.11.0 -tox==3.12.1 -testinfra==1.19.0 +tox==3.13.2 +testinfra==3.0.5 diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..ffe1fcd --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,6 @@ +--- + +- name: 'INSTALL | install procmail' + apt: + name: 'procmail' + state: 'present' diff --git a/tasks/main.yml b/tasks/main.yml index 6ec0ea9..516757a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,6 +8,12 @@ - 'role::systemd-notify' - 'role::systemd-notify::init' +- name: 'INSTALL | Install package with lockfile' + become: True + include_tasks: "{{ role_path }}/tasks/install.yml" + tags: + - 'role::systemd-notify' + - 'role::systemd-notify::install' - name: 'CONFIG | Manage config tasks' become: 'True' diff --git a/templates/systemd.email.j2 b/templates/systemd.email.j2 index 3f54cbf..13454dd 100644 --- a/templates/systemd.email.j2 +++ b/templates/systemd.email.j2 @@ -1,13 +1,22 @@ #!/bin/bash -file=$(mktemp) +ERRORMAIL=$(mktemp) +LOCKFILE="/var/lock/$2" +FROMAIL="{{ notify_fromEmail }}" +SUBJECT=$(hostname -f) +set -eux -echo "TO: $1" >> $file -echo "From: admin@temelio.com" >> $file -echo "Subject: $HOSTNAME - $2" >> $file -echo "Content-Transfer-Encoding: 8bit" >> $file -echo "Content-Type: text/plain; charset=UTF-8" >> $file -echo "$(systemctl status --full "$2")" >> $file -echo "------------------------- logs tail -n 100 ------------------------" >> $file -echo "$(journalctl -n 100 -u "$2")" >> $file -cat $file |/usr/sbin/sendmail -t; -rm $file; +if lockfile -r0 -l900 $LOCKFFILE; then + echo "TO: $1" >> $ERRORMAIL + echo "From: $FROMAIL" >> $ERRORMAIL + echo "Subject: $SUBJECT - $2" >> $ERRORMAIL + echo "Content-Transfer-Encoding: 8bit" >> $ERRORMAIL + echo "Content-Type: text/plain; charset=UTF-8" >> $ERRORMAIL + echo "$(systemctl status --full "$2")" >> $ERRORMAIL + echo "------------------------- logs tail -n 100 ------------------------" >> $ERRORMAIL + echo "$(journalctl -n 100 -u "$2")" >> $ERRORMAIL + cat $ERRORMAIL |/usr/sbin/sendmail -t; + rm $ERRORMAIL; +else + echo 1>&2 "Fatal error: another process has been keeping the lock for too long or the lock file is inaccessible" + exit 3 +fi