From 4d6b068ce3e0d576fa104801239776a02c23701d Mon Sep 17 00:00:00 2001 From: Mason James Date: Wed, 12 Oct 2022 13:05:45 +1300 Subject: [PATCH] Bug 31729: Enable automatic filesystem refresh in Plack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" to test: 0/ apt install inotify-tools 1/ apply patch 2/ copy files, and set perms manually sudo cp debian/script/koha-plack /usr/sbin sudo cp debian/script/koha-watcher to /usr/sbin sudo chmod 755 debian/script/koha-plack /usr/sbin/koha-plack sudo chmod 755 debian/script/koha-watcher to /usr/sbin/koha-watcher 3/ koha-plack --start --watch kohadev 4/ pat a kitten 🐱 5/ modify file in watched dir echo `date` > /usr/share/koha/xxx1 echo `date` > /usr/share/koha/xxx2 6/ see HUP/inotify messages in log file $ tail -f /var/log/koha/kohadev/plack-error.log /usr/share/koha/ MODIFY xxx1 Sending children hup signal /usr/share/koha/ MODIFY xxx2 Sending children hup signal 7/ observe koha-watch process ps -ef | grep koha-watcher | grep -v grep | wc -l 1 8/ koha-plack --stop kohadev 9/ observe no koha-watch process ps -ef | grep koha-watcher | grep -v grep | wc -l 0 --- debian/control.in | 1 + debian/koha-common.install | 1 + debian/scripts/koha-plack | 34 +++++++++++++++++++ debian/scripts/koha-watcher | 66 +++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100755 debian/scripts/koha-watcher diff --git a/debian/control.in b/debian/control.in index e1efe67d3a..9aa8bfc864 100644 --- a/debian/control.in +++ b/debian/control.in @@ -23,6 +23,7 @@ Depends: ${misc:Depends}, ${koha:Depends}, daemon, debconf, idzebra-2.0, + inotify-tools, memcached, mysql-client | virtual-mysql-client, perl-doc, diff --git a/debian/koha-common.install b/debian/koha-common.install index 2f5c793d11..219d944107 100644 --- a/debian/koha-common.install +++ b/debian/koha-common.install @@ -33,6 +33,7 @@ debian/scripts/koha-sitemap usr/sbin debian/scripts/koha-translate usr/sbin debian/scripts/koha-upgrade-schema usr/sbin debian/scripts/koha-upgrade-to-3.4 usr/sbin +debian/scripts/koha-watcher usr/sbin debian/scripts/koha-worker usr/sbin debian/scripts/koha-z3950-responder usr/sbin debian/scripts/koha-zebra usr/sbin diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack index 6fe1860268..029ea9da71 100755 --- a/debian/scripts/koha-plack +++ b/debian/scripts/koha-plack @@ -62,6 +62,8 @@ $scriptname -h|--help --debugger-path Specify the path for the debugger library --quiet|-q Make the script quiet about non existent instance names (useful for calling from another scripts). + --watch|-w Enable automatic reload to starman/plack when a file + is modified (intended for development use) --help|-h Display this help message EOF @@ -131,6 +133,11 @@ start_plack() # Go back to the original dir cd "$current_dir" + # start watcher + if [ "${watch}" = "yes" ]; then + start_watcher $instancename + fi + else log_daemon_msg "Error: Plack already running for ${instancename}" log_end_msg 1 @@ -152,12 +159,19 @@ stop_plack() else log_end_msg 1 fi + + # stop watcher + if [ -f /var/run/koha/${instancename}/watcher.pid ]; then + stop_watcher $instancename + fi + else log_daemon_msg "Error: Plack not running for ${instancename}" log_end_msg 1 fi } + restart_plack() { local instancename=$1 @@ -294,6 +308,22 @@ disable_plack() fi } +start_watcher() +{ + local instancename=$1 + PIDFILE="/var/run/koha/${instancename}/watcher.pid" + start-stop-daemon --pidfile ${PIDFILE} --start --background \ + --make-pidfile --startas /usr/sbin/koha-watcher \ + -- -d $KOHA_HOME ${instancename} +} + +stop_watcher() +{ + local instancename=$1 + PID=`cat /var/run/koha/${instancename}/watcher.pid` + start-stop-daemon --ppid ${PID} --stop --retry=QUIT/5/KILL/10 +} + check_env_and_warn() { local apache_version_ok="no" @@ -401,6 +431,7 @@ _do_instance() { STARMAN=$(which starman) op="" quiet="no" +watch="no" debug_mode="no" debugger_key="" debugger_location="localhost:9000" @@ -415,6 +446,9 @@ while [ $# -gt 0 ]; do -q|--quiet) quiet="yes" shift ;; + -w|--watch) + watch="yes" + shift ;; --start) set_action "start" shift ;; diff --git a/debian/scripts/koha-watcher b/debian/scripts/koha-watcher new file mode 100755 index 0000000000..b21e40a16b --- /dev/null +++ b/debian/scripts/koha-watcher @@ -0,0 +1,66 @@ +#!/bin/sh +# +# koha-watcher -- Restart starman when a file is modified. +# Copyright 2022 Mason James +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +set -e + +usage() +{ + local scriptname=$(basename $0) + + cat <