From 37f7d3eeaf3801d93c45faafbe6b2e0a6c9f3b7b Mon Sep 17 00:00:00 2001 From: root Date: Mon, 26 Dec 2022 16:03:19 -0500 Subject: [PATCH 1/3] Too many global vars: put {{ systemctl_program }} to rest --- roles/kiwix/defaults/main.yml | 1 - roles/kiwix/tasks/enable-or-disable.yml | 2 +- roles/kiwix/templates/iiab-make-kiwix-lib | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/roles/kiwix/defaults/main.yml b/roles/kiwix/defaults/main.yml index 24c1ff0a9..2696974fd 100644 --- a/roles/kiwix/defaults/main.yml +++ b/roles/kiwix/defaults/main.yml @@ -57,6 +57,5 @@ kiwix_url: /kiwix kiwix_url_plus_slash: "{{ kiwix_url }}/" # /kiwix/ kiwix_path: "{{ iiab_base }}/kiwix" # /opt/iiab/kiwix -systemctl_program: /bin/systemctl kiwix_nginx_timeout: 600 kiwix_threads: 4 diff --git a/roles/kiwix/tasks/enable-or-disable.yml b/roles/kiwix/tasks/enable-or-disable.yml index c3b2d617c..6487d84a2 100644 --- a/roles/kiwix/tasks/enable-or-disable.yml +++ b/roles/kiwix/tasks/enable-or-disable.yml @@ -26,7 +26,7 @@ - name: Make a crontab entry to restart kiwix-serve at 4AM (debuntu) lineinfile: # mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed - line: "0 4 * * * root /bin/systemctl restart kiwix-serve.service" + line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service" dest: /etc/crontab when: kiwix_enabled diff --git a/roles/kiwix/templates/iiab-make-kiwix-lib b/roles/kiwix/templates/iiab-make-kiwix-lib index e69271949..f945bf2a4 100644 --- a/roles/kiwix/templates/iiab-make-kiwix-lib +++ b/roles/kiwix/templates/iiab-make-kiwix-lib @@ -25,12 +25,12 @@ if flock -n -e 200; then : else /usr/bin/iiab-make-kiwix-lib.py -f # force rebuild of library.xml fi - {{ systemctl_program }} stop kiwix-serve + /usr/bin/systemctl stop kiwix-serve if [ -f $KIWIXLIB ]; then rm $KIWIXLIB fi mv $KIWIXLIB.tmp $KIWIXLIB - {{ systemctl_program }} start kiwix-serve + /usr/bin/systemctl start kiwix-serve else echo "Can't get wait lock for iiab-make-kiwix-lib.py"; exit 1; From f9b5e74d8a19ff56364c5a67be474d4af32f8ba9 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 26 Dec 2022 18:30:03 -0500 Subject: [PATCH 2/3] Enable/Disable kiwix-serve 4AM daily cron (using Ansible) --- roles/kiwix/tasks/enable-or-disable.yml | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/roles/kiwix/tasks/enable-or-disable.yml b/roles/kiwix/tasks/enable-or-disable.yml index 6487d84a2..493ec86f7 100644 --- a/roles/kiwix/tasks/enable-or-disable.yml +++ b/roles/kiwix/tasks/enable-or-disable.yml @@ -17,19 +17,35 @@ when: kiwix_enabled -# TO DO: BOTH CRON ENTRIES BELOW *SHOULD* BE DELETED "when: not kiwix_enabled" - # In the past kiwix-serve did not stay running, so we'd been doing this hourly. # @mgautierfr & others suggest kiwix-serve might be auto-restarted w/o cron in # future, whenever service fails, if this really catches all cases?? # https://github.com/iiab/iiab/issues/484#issuecomment-342151726 -- name: Make a crontab entry to restart kiwix-serve at 4AM (debuntu) - lineinfile: - # mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed - line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service" - dest: /etc/crontab + +- name: Set cron to restart kiwix-serve 4AM daily, if kiwix_enabled + cron: + name: kiwix-serve daily restart + minute: "0" + hour: "4" + job: /usr/bin/systemctl restart kiwix-serve.service + user: root + cron_file: kiwix-serve_daily # i.e. /etc/cron.d/kiwix-serve_daily instead of /var/spool/cron/crontabs/root when: kiwix_enabled +- name: Remove 4AM daily cron, if not kiwix_enabled + cron: + name: kiwix-serve daily restart + cron_file: kiwix-serve_daily + state: absent + when: not kiwix_enabled + +# - name: Make a crontab entry to restart kiwix-serve at 4AM (debuntu) +# lineinfile: +# # mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed +# line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service" +# dest: /etc/crontab +# when: kiwix_enabled + # - name: Make a crontab entry to restart kiwix-serve at 4AM (redhat) # # * * * * * user-name command to be executed # lineinfile: From f082df8ef42103d047b2df15a89615c67841f987 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Dec 2022 07:17:09 -0500 Subject: [PATCH 3/3] /etc/cron.d/kiwix-serve_daily instead of defaults --- roles/kiwix/tasks/enable-or-disable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/kiwix/tasks/enable-or-disable.yml b/roles/kiwix/tasks/enable-or-disable.yml index 493ec86f7..0381ae2cd 100644 --- a/roles/kiwix/tasks/enable-or-disable.yml +++ b/roles/kiwix/tasks/enable-or-disable.yml @@ -29,7 +29,7 @@ hour: "4" job: /usr/bin/systemctl restart kiwix-serve.service user: root - cron_file: kiwix-serve_daily # i.e. /etc/cron.d/kiwix-serve_daily instead of /var/spool/cron/crontabs/root + cron_file: kiwix-serve_daily # i.e. /etc/cron.d/kiwix-serve_daily instead of /var/spool/cron/crontabs/root or /etc/crontab when: kiwix_enabled - name: Remove 4AM daily cron, if not kiwix_enabled