Bugzilla – Attachment 148600 Details for
Bug 31729
Enable automatic filesystem refresh in Plack
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31729: Enable automatic filesystem refresh in Plack
Bug-31729-Enable-automatic-filesystem-refresh-in-P.patch (text/plain), 7.48 KB, created by
Mason James
on 2023-03-23 10:26:36 UTC
(
hide
)
Description:
Bug 31729: Enable automatic filesystem refresh in Plack
Filename:
MIME Type:
Creator:
Mason James
Created:
2023-03-23 10:26:36 UTC
Size:
7.48 KB
patch
obsolete
>From 8e3dabc554d4608fdede93c48aef1ffcc41e691b Mon Sep 17 00:00:00 2001 >From: Mason James <mtj@kohaaloha.com> >Date: Wed, 12 Oct 2022 13:05:45 +1300 >Subject: [PATCH] Bug 31729: Enable automatic filesystem refresh in Plack > >to test (on KTD) > >- install inotify-tools > $ sudo apt install inotify-tools > >- apply patch > $ git bz apply 31729 > >- manually install files and set perms > $ cd /kohadevbox/koha > $ sudo cp debian/scripts/koha-plack /usr/sbin > $ sudo cp debian/scripts/koha-watcher /usr/sbin > $ sudo chmod 755 /usr/sbin/koha-plack > $ sudo chmod 755 /usr/sbin/koha-watcher > >- restart, with --watch arg > $ sudo koha-plack --restart --watch kohadev > >- observe koha-watch process > $ ps -ef | grep koha-watcher | grep -v grep | wc -l > 3 > >- modify some perl files in watched dir > $ echo `date` > /kohadevbox/koha/xxx.pl > $ echo `date` > /kohadevbox/koha/xxx.pm > >- see HUP/inotify messages in log file > $ tail -f /var/log/koha/kohadev/plack-error.log > CLOSE_WRITE,CLOSE happened to xxx.pl in /kohadevbox/koha/ > CLOSE_WRITE,CLOSE happened to xxx.pm in /kohadevbox/koha/ > Sending children hup signal > >- stop koha-plack > $ sudo koha-plack --stop kohadev > >- 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 | 40 ++++++++++++++++- > debian/scripts/koha-watcher | 88 +++++++++++++++++++++++++++++++++++++ > 4 files changed, 129 insertions(+), 1 deletion(-) > create mode 100755 debian/scripts/koha-watcher > >diff --git a/debian/control.in b/debian/control.in >index 2b2b206748..8a134d1781 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..44a1bcff4d 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 >@@ -145,19 +152,26 @@ stop_plack() > > if is_plack_running ${instancename}; then > >+ # stop watcher >+ if [ -f "/var/run/koha/${instancename}/watcher.pid" ]; then >+ stop_watcher "$instancename" >+ fi >+ > log_daemon_msg "Stopping Plack daemon for ${instancename}" > >- if start-stop-daemon --pidfile ${PIDFILE} --user="${instancename}-koha" --stop --retry=QUIT/30/KILL/5; then >+ if start-stop-daemon --pidfile "${PIDFILE}" --user="${instancename}-koha" --stop --retry=QUIT/30/KILL/5; then > log_end_msg 0 > else > log_end_msg 1 > fi >+ > else > log_daemon_msg "Error: Plack not running for ${instancename}" > log_end_msg 1 > fi > } > >+ > restart_plack() > { > local instancename=$1 >@@ -294,6 +308,26 @@ disable_plack() > fi > } > >+start_watcher() >+{ >+ local instancename="$1" >+ local 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" >+ local PIDFILE="/var/run/koha/$instancename/watcher.pid" >+ local PID=$(cat "$PIDFILE") >+ >+ start-stop-daemon --ppid "$PID" --stop -v >+ rm "$PIDFILE" >+} >+ > check_env_and_warn() > { > local apache_version_ok="no" >@@ -401,6 +435,7 @@ _do_instance() { > STARMAN=$(which starman) > op="" > quiet="no" >+watch="no" > debug_mode="no" > debugger_key="" > debugger_location="localhost:9000" >@@ -415,6 +450,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..6c25928628 >--- /dev/null >+++ b/debian/scripts/koha-watcher >@@ -0,0 +1,88 @@ >+#!/bin/dash >+# >+# 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 <<EOF >+$scriptname >+ >+This script restarts starman when a file is modified, called from 'koha-plack --start --watch instance' >+ >+Not intended to be run manually >+ >+Usage: >+$scriptname --dir /path/to/my/repo instancename >+$scriptname -h|--help >+ >+ --dir|-d Path of directory to be watched >+ --sec|-s Seconds between reloads (default is 2) >+ --help|-h Display this help message >+ >+EOF >+} >+ >+sec=2 >+# Read command line parameters >+while [ $# -gt 0 ]; do >+ case "$1" in >+ -h|--help) >+ usage ; exit 0 ;; >+ -d|--dir) >+ dir="$2" >+ shift 2 ;; >+ -s|--sec) >+ sec="$2" >+ shift 2 ;; >+ *) >+ # We expect the remaining stuff are the instance names >+ instance=$1 >+ break ;; >+ esac >+done >+ >+if [ -z "$dir" ]; then >+ echo "Error: you must provide a directory name" >+ exit >+elif [ -z "$instance" ]; then >+ echo "Error: you must provide an instance name" >+ exit >+fi >+ >+tmpfile="/var/log/koha/$instance/koha-watcher.tmp" >+logfile="/var/log/koha/$instance/plack-error.log" >+ >+# watch perl files in a dir >+watch_dir() { >+inotifywait --recursive -m --event CLOSE_WRITE "$dir" | \ >+ grep -E '\.pl$|\.pm$' --line-buffered | \ >+ while read -r path events file; do >+ echo "$events happened to $file in $path" | tee -a "$tmpfile" "$logfile" >+ done; >+} >+ >+start_reload_loop() { >+ while true; do >+ # restart, if logfile exists >+ if [ -e "$tmpfile" ]; then >+ kill -s HUP $(cat /var/run/koha/"$instance"/plack.pid) >+ rm "$tmpfile" >+ fi >+ sleep $sec >+ done; >+} >+ >+start_reload_loop & >+watch_dir >+ >+exit 0 >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31729
:
141577
|
141578
|
141596
|
141597
|
141598
|
141714
|
141715
|
141716
|
142043
|
142044
|
142050
|
148600
|
148602
|
148603
|
148606
|
148612
|
148613
|
148720
|
154542
|
154601
|
154605
|
154676
|
154677