diff --git a/roles/kiwix/templates/iiab-make-kiwix-lib b/roles/kiwix/templates/iiab-make-kiwix-lib index a7d2b7818..5680470f3 100644 --- a/roles/kiwix/templates/iiab-make-kiwix-lib +++ b/roles/kiwix/templates/iiab-make-kiwix-lib @@ -1,25 +1,30 @@ -#!/bin/bash - -LOCK_PATH=/run/lock/kiwix -WAITLOCK="$LOCK_PATH/make-kiwix-lib-wait.LCK"; -RUNLOCK=WAITLOCK="$LOCK_PATH/make-kiwix-lib-run.LCK"; -exec 200>$WAITLOCK; -exec 201>$RUNLOCK; - -if flock -n -e 200; then : - echo 'Waiting to run iiab-make-kiwix-lib.py' - # wait for up to 5 min - flock -x -w 300 201 - echo "Now running iiab-make-kiwix-lib.py" - # write to {{ kiwix_library_xml }}.tmp to minimize kiwix down - # zim map could be out of sync for a few seconds - /usr/bin/iiab-make-kiwix-lib.py - {{ systemctl_program }} stop kiwix-serve - rm {{ kiwix_library_xml }} - mv {{ kiwix_library_xml }}.tmp {{ kiwix_library_xml }} - {{ systemctl_program }} start kiwix-serve -else - echo "Can't get wait lock for iiab-make-kiwix-lib.py"; - exit 1; -fi -exit 0 +#!/bin/bash + +LOCK_PATH=/run/lock/kiwix +mkdir -p $LOCK_PATH + +WAITLOCK="$LOCK_PATH/make-kiwix-lib-wait.LCK"; +RUNLOCK="$LOCK_PATH/kiwix-lib-access.LCK"; +KIWIXLIB={{ kiwix_library_xml }} + +exec 200>$WAITLOCK; +exec 201>$RUNLOCK; + +if flock -n -e 200; then : + echo 'Waiting to run iiab-make-kiwix-lib.py' + # wait for up to 5 min + flock -x -w 300 201 + flock -u 200 # unlock queue + echo "Now running iiab-make-kiwix-lib.py" + # write to {{ kiwix_library_xml }}.tmp to minimize kiwix down + # zim map could be out of sync for a few seconds + /usr/bin/iiab-make-kiwix-lib.py + {{ systemctl_program }} stop kiwix-serve + rm $KIWIXLIB + mv $KIWIXLIB.tmp $KIWIXLIB + {{ systemctl_program }} start kiwix-serve +else + echo "Can't get wait lock for iiab-make-kiwix-lib.py"; + exit 1; +fi +exit 0 diff --git a/roles/kiwix/templates/iiab-make-kiwix-lib.py b/roles/kiwix/templates/iiab-make-kiwix-lib.py index 6a06728dc..d331f194d 100644 --- a/roles/kiwix/templates/iiab-make-kiwix-lib.py +++ b/roles/kiwix/templates/iiab-make-kiwix-lib.py @@ -2,7 +2,7 @@ """ - Creates library.xml file for kiwix from contents of /zims/content and index + Creates temp library.xml file for kiwix from contents of /zims/content and index Author: Tim Moody Contributors: Jerry Vonau @@ -30,7 +30,9 @@ iiab_config_file = "{{ iiab_config_file }}" # Variables that should be read from config file # All of these variables will be read from config files and recomputed in init() iiab_zim_path = "{{ iiab_zim_path }}" -kiwix_library_xml = "{{ kiwix_library_xml }}.tmp" + +# Later we will append .tmp to file name +kiwix_library_xml = "{{ kiwix_library_xml }}" iiab_base_path = "{{ iiab_base }}" kiwix_manage = iiab_base_path + "/kiwix/bin/kiwix-manage" @@ -41,8 +43,9 @@ old_zim_map = {"bad.zim" : "unparseable name"} def main(): """Server routine""" - + global kiwix_library_xml init() + kiwix_library_xml += '.tmp' # write to temp file # remove existing file try: