View | Details | Raw Unified | Return to bug 31729
Collapse All | Expand All

(-)a/debian/control.in (+1 lines)
Lines 23-28 Depends: ${misc:Depends}, ${koha:Depends}, Link Here
23
 daemon,
23
 daemon,
24
 debconf,
24
 debconf,
25
 idzebra-2.0,
25
 idzebra-2.0,
26
 inotify-tools,
26
 memcached,
27
 memcached,
27
 mysql-client | virtual-mysql-client,
28
 mysql-client | virtual-mysql-client,
28
 perl-doc,
29
 perl-doc,
(-)a/debian/koha-common.install (+1 lines)
Lines 33-38 debian/scripts/koha-sitemap usr/sbin Link Here
33
debian/scripts/koha-translate               usr/sbin
33
debian/scripts/koha-translate               usr/sbin
34
debian/scripts/koha-upgrade-schema          usr/sbin
34
debian/scripts/koha-upgrade-schema          usr/sbin
35
debian/scripts/koha-upgrade-to-3.4          usr/sbin
35
debian/scripts/koha-upgrade-to-3.4          usr/sbin
36
debian/scripts/koha-watcher                 usr/sbin
36
debian/scripts/koha-worker                  usr/sbin
37
debian/scripts/koha-worker                  usr/sbin
37
debian/scripts/koha-z3950-responder         usr/sbin
38
debian/scripts/koha-z3950-responder         usr/sbin
38
debian/scripts/koha-zebra                   usr/sbin
39
debian/scripts/koha-zebra                   usr/sbin
(-)a/debian/scripts/koha-plack (-1 / +39 lines)
Lines 62-67 $scriptname -h|--help Link Here
62
    --debugger-path       Specify the path for the debugger library
62
    --debugger-path       Specify the path for the debugger library
63
    --quiet|-q            Make the script quiet about non existent instance names
63
    --quiet|-q            Make the script quiet about non existent instance names
64
                          (useful for calling from another scripts).
64
                          (useful for calling from another scripts).
65
    --watch|-w            Enable automatic reload to starman/plack when a file
66
                           is modified (intended for development use)
65
    --help|-h             Display this help message
67
    --help|-h             Display this help message
66
68
67
EOF
69
EOF
Lines 131-136 start_plack() Link Here
131
        # Go back to the original dir
133
        # Go back to the original dir
132
        cd "$current_dir"
134
        cd "$current_dir"
133
135
136
        # start watcher
137
        if [ "${watch}" = "yes" ]; then
138
            start_watcher "$instancename"
139
        fi
140
134
    else
141
    else
135
        log_daemon_msg "Error: Plack already running for ${instancename}"
142
        log_daemon_msg "Error: Plack already running for ${instancename}"
136
        log_end_msg 1
143
        log_end_msg 1
Lines 145-163 stop_plack() Link Here
145
152
146
    if is_plack_running ${instancename}; then
153
    if is_plack_running ${instancename}; then
147
154
155
        # stop watcher
156
        if [ -f "/var/run/koha/${instancename}/watcher.pid" ]; then
157
            stop_watcher "$instancename"
158
        fi
159
148
        log_daemon_msg "Stopping Plack daemon for ${instancename}"
160
        log_daemon_msg "Stopping Plack daemon for ${instancename}"
149
161
150
        if start-stop-daemon --pidfile ${PIDFILE} --user="${instancename}-koha" --stop --retry=QUIT/30/KILL/5; then
162
        if start-stop-daemon --pidfile "${PIDFILE}" --user="${instancename}-koha" --stop --retry=QUIT/30/KILL/5; then
151
            log_end_msg 0
163
            log_end_msg 0
152
        else
164
        else
153
            log_end_msg 1
165
            log_end_msg 1
154
        fi
166
        fi
167
155
    else
168
    else
156
        log_daemon_msg "Error: Plack not running for ${instancename}"
169
        log_daemon_msg "Error: Plack not running for ${instancename}"
157
        log_end_msg 1
170
        log_end_msg 1
158
    fi
171
    fi
159
}
172
}
160
173
174
161
restart_plack()
175
restart_plack()
162
{
176
{
163
    local instancename=$1
177
    local instancename=$1
Lines 294-299 disable_plack() Link Here
294
    fi
308
    fi
295
}
309
}
296
310
311
start_watcher()
312
{
313
    local instancename="$1"
314
    local PIDFILE="/var/run/koha/${instancename}/watcher.pid"
315
316
    start-stop-daemon --pidfile "$PIDFILE" --start --background \
317
        --make-pidfile --startas /usr/sbin/koha-watcher \
318
        -- -d $KOHA_HOME "$instancename"
319
}
320
321
stop_watcher()
322
{
323
    local instancename="$1"
324
    local PIDFILE="/var/run/koha/$instancename/watcher.pid"
325
    local PID=$(cat "$PIDFILE")
326
327
    start-stop-daemon --ppid "$PID" --stop -v
328
    rm "$PIDFILE"
329
}
330
297
check_env_and_warn()
331
check_env_and_warn()
298
{
332
{
299
    local apache_version_ok="no"
333
    local apache_version_ok="no"
Lines 401-406 _do_instance() { Link Here
401
STARMAN=$(which starman)
435
STARMAN=$(which starman)
402
op=""
436
op=""
403
quiet="no"
437
quiet="no"
438
watch="no"
404
debug_mode="no"
439
debug_mode="no"
405
debugger_key=""
440
debugger_key=""
406
debugger_location="localhost:9000"
441
debugger_location="localhost:9000"
Lines 415-420 while [ $# -gt 0 ]; do Link Here
415
        -q|--quiet)
450
        -q|--quiet)
416
            quiet="yes"
451
            quiet="yes"
417
            shift ;;
452
            shift ;;
453
        -w|--watch)
454
            watch="yes"
455
            shift ;;
418
        --start)
456
        --start)
419
            set_action "start"
457
            set_action "start"
420
            shift ;;
458
            shift ;;
(-)a/debian/scripts/koha-watcher (-1 / +88 lines)
Line 0 Link Here
0
- 
1
#!/bin/dash
2
#
3
# koha-watcher -- Restart starman when a file is modified.
4
# Copyright 2022  Mason James
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
11
set -e
12
13
usage()
14
{
15
    local scriptname=$(basename "$0")
16
17
    cat <<EOF
18
$scriptname
19
20
This script restarts starman when a file is modified, called from 'koha-plack --start --watch instance'
21
22
Not intended to be run manually
23
24
Usage:
25
$scriptname --dir /path/to/my/repo instancename
26
$scriptname -h|--help
27
28
    --dir|-d              Path of directory to be watched
29
    --sec|-s              Seconds between reloads (default is 2)
30
    --help|-h             Display this help message
31
32
EOF
33
}
34
35
sec=2
36
# Read command line parameters
37
while [ $# -gt 0 ]; do
38
    case "$1" in
39
        -h|--help)
40
            usage ; exit 0 ;;
41
        -d|--dir)
42
            dir="$2"
43
            shift 2 ;;
44
        -s|--sec)
45
            sec="$2"
46
            shift 2 ;;
47
        *)
48
            # We expect the remaining stuff are the instance names
49
            instance=$1
50
            break ;;
51
    esac
52
done
53
54
if [ -z "$dir" ]; then
55
        echo "Error: you must provide a directory name"
56
        exit
57
elif [ -z "$instance" ]; then
58
        echo "Error: you must provide an instance name"
59
        exit
60
fi
61
62
tmpfile="/var/log/koha/$instance/koha-watcher.tmp"
63
logfile="/var/log/koha/$instance/plack-error.log"
64
65
# watch perl files in a dir
66
watch_dir() {
67
inotifywait  --recursive -m  --event CLOSE_WRITE "$dir" | \
68
    grep -E '\.pl$|\.pm$' --line-buffered | \
69
    while read -r path events file; do
70
            echo "$events happened to $file in $path" | tee -a  "$tmpfile" "$logfile"
71
    done;
72
}
73
74
start_reload_loop() {
75
    while true; do
76
        # restart, if logfile exists
77
        if [ -e "$tmpfile" ]; then
78
            kill -s HUP $(cat /var/run/koha/"$instance"/plack.pid)
79
            rm "$tmpfile"
80
        fi
81
        sleep $sec
82
    done;
83
}
84
85
start_reload_loop &
86
watch_dir
87
88
exit 0

Return to bug 31729