Line 0
Link Here
|
|
|
1 |
#!/bin/bash |
2 |
# |
3 |
# Copyright 2015 Theke Solutions |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# This program is free software: you can redistribute it and/or modify |
8 |
# it under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation, either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# This program is distributed in the hope that it will be useful, |
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 |
|
20 |
set -e |
21 |
|
22 |
. /lib/lsb/init-functions |
23 |
|
24 |
# Read configuration variable file if it is present |
25 |
[ -r /etc/default/koha-common ] && . /etc/default/koha-common |
26 |
|
27 |
# include helper functions |
28 |
if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then |
29 |
. "/usr/share/koha/bin/koha-functions.sh" |
30 |
else |
31 |
echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2 |
32 |
exit 1 |
33 |
fi |
34 |
|
35 |
usage() |
36 |
{ |
37 |
local scriptname=$(basename $0) |
38 |
|
39 |
cat <<EOF |
40 |
$scriptname |
41 |
|
42 |
This script lets you manage the plack daemons for your Koha instances. |
43 |
|
44 |
Usage: |
45 |
$scriptname --start|--stop|--restart [--quiet|-q] instancename1 [instancename2...] |
46 |
$scriptname --enable|--disable instancename1 [instancename2] |
47 |
$scriptname -h|--help |
48 |
|
49 |
--start Start the plack daemon for the specified instances |
50 |
--stop Stop the plack daemon for the specified instances |
51 |
--restart Restart the plack daemon for the specified instances |
52 |
--enable Enable plack for the specified instances |
53 |
--disable Disable plack for the specified instances |
54 |
--quiet|-q Make the script quiet about non existent instance names |
55 |
(useful for calling from another scripts). |
56 |
--help|-h Display this help message |
57 |
|
58 |
EOF |
59 |
} |
60 |
|
61 |
start_plack() |
62 |
{ |
63 |
local instancename=$1 |
64 |
|
65 |
local PIDFILE="/var/run/koha/${instancename}/plack.pid" |
66 |
local PLACKSOCKET="/var/run/koha/${instancename}/plack.sock" |
67 |
local PSGIFILE="/etc/koha/plack.psgi" |
68 |
local NAME="${instancename}-koha-plack" |
69 |
|
70 |
STARMANOPTS="-M FindBin --max-requests 50 --workers 2 \ |
71 |
--user=${instancename}-koha --group ${instancename}-koha \ |
72 |
--pid ${PIDFILE} \ |
73 |
--daemonize \ |
74 |
--access-log /var/log/koha/${instancename}/plack.log \ |
75 |
--error-log /var/log/koha/${instancename}/plack-error.log \ |
76 |
-E deployment --socket ${PLACKSOCKET} ${PSGIFILE}" |
77 |
|
78 |
if ! is_plack_running ${instancename}; then |
79 |
export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml" |
80 |
|
81 |
log_daemon_msg "Starting Plack daemon for ${instancename}" |
82 |
|
83 |
if ${STARMAN} ${STARMANOPTS}; then |
84 |
log_end_msg 0 |
85 |
else |
86 |
log_end_msg 1 |
87 |
fi |
88 |
else |
89 |
log_daemon_msg "Error: Plack already running for ${instancename}" |
90 |
log_end_msg 1 |
91 |
fi |
92 |
} |
93 |
|
94 |
stop_plack() |
95 |
{ |
96 |
local instancename=$1 |
97 |
|
98 |
local PIDFILE="/var/run/koha/${instancename}/plack.pid" |
99 |
|
100 |
if is_plack_running ${instancename}; then |
101 |
|
102 |
log_daemon_msg "Stopping Plack daemon for ${instancename}" |
103 |
|
104 |
if start-stop-daemon --pidfile ${PIDFILE} --stop; then |
105 |
log_end_msg 0 |
106 |
else |
107 |
log_end_msg 1 |
108 |
fi |
109 |
else |
110 |
log_daemon_msg "Error: Plack not running for ${instancename}" |
111 |
log_end_msg 1 |
112 |
fi |
113 |
} |
114 |
|
115 |
restart_plack() |
116 |
{ |
117 |
local instancename=$1 |
118 |
|
119 |
local PIDFILE="/var/run/koha/${instancename}/plack.pid" |
120 |
|
121 |
if is_plack_running ${instancename}; then |
122 |
|
123 |
log_daemon_msg "Restarting Plack daemon for ${instancename}" |
124 |
|
125 |
if stop_plack $instancename && start_plack $instancename; then |
126 |
log_end_msg 0 |
127 |
else |
128 |
log_end_msg 1 |
129 |
fi |
130 |
else |
131 |
log_daemon_msg "Error: Plack not running for ${instancename}" |
132 |
log_end_msg 1 |
133 |
fi |
134 |
} |
135 |
|
136 |
enable_plack() |
137 |
{ |
138 |
local instancename=$1 |
139 |
local instancefile=$(get_apache_config_for "$instancename") |
140 |
|
141 |
if ! is_plack_enabled $instancename; then |
142 |
# Uncomment the plack related lines for OPAC and intranet |
143 |
sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:\1:' "$instancefile" |
144 |
sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:\1:' "$instancefile" |
145 |
return 0 |
146 |
else |
147 |
return 1 |
148 |
fi |
149 |
} |
150 |
|
151 |
disable_plack() |
152 |
{ |
153 |
local instancename=$1 |
154 |
local instancefile=$(get_apache_config_for "$instancename") |
155 |
|
156 |
if is_plack_enabled $instancename; then |
157 |
# Comment out the plack related lines for OPAC and intranet |
158 |
sed -i 's:^\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:#\1:' "$instancefile" |
159 |
sed -i 's:^\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:#\1:' "$instancefile" |
160 |
return 0 |
161 |
else |
162 |
return 1 |
163 |
fi |
164 |
} |
165 |
|
166 |
set_action() |
167 |
{ |
168 |
if [ "$op" = "" ]; then |
169 |
op=$1 |
170 |
else |
171 |
die "Error: only one action can be specified." |
172 |
fi |
173 |
} |
174 |
|
175 |
STARMAN=$(which starman) |
176 |
op="" |
177 |
quiet="no" |
178 |
|
179 |
# Read command line parameters |
180 |
while [ $# -gt 0 ]; do |
181 |
|
182 |
case "$1" in |
183 |
-h|--help) |
184 |
usage ; exit 0 ;; |
185 |
-q|--quiet) |
186 |
quiet="yes" |
187 |
shift ;; |
188 |
--start) |
189 |
set_action "start" |
190 |
shift ;; |
191 |
--stop) |
192 |
set_action "stop" |
193 |
shift ;; |
194 |
--restart) |
195 |
set_action "restart" |
196 |
shift ;; |
197 |
--enable) |
198 |
set_action "enable" |
199 |
shift ;; |
200 |
--disable) |
201 |
set_action "disable" |
202 |
shift ;; |
203 |
-*) |
204 |
die "Error: invalid option switch ($1)" ;; |
205 |
*) |
206 |
# We expect the remaining stuff are the instance names |
207 |
break ;; |
208 |
esac |
209 |
|
210 |
done |
211 |
|
212 |
if [ -z $PERL5LIB ]; then |
213 |
PERL5LIB="/usr/share/koha/lib" |
214 |
fi |
215 |
|
216 |
export PERL5LIB |
217 |
|
218 |
if [ $# -gt 0 ]; then |
219 |
# We have at least one instance name |
220 |
for name in "$@"; do |
221 |
|
222 |
if is_instance $name; then |
223 |
|
224 |
case $op in |
225 |
"start") |
226 |
start_plack $name |
227 |
;; |
228 |
"stop") |
229 |
stop_plack $name |
230 |
;; |
231 |
"restart") |
232 |
restart_plack $name |
233 |
;; |
234 |
"enable") |
235 |
enable_plack $name |
236 |
;; |
237 |
"disable") |
238 |
disable_plack $name |
239 |
;; |
240 |
esac |
241 |
|
242 |
else |
243 |
if [ "$quiet" = "no" ]; then |
244 |
log_daemon_msg "Error: Invalid instance name $name" |
245 |
log_end_msg 1 |
246 |
fi |
247 |
fi |
248 |
|
249 |
done |
250 |
else |
251 |
if [ "$quiet" = "no" ]; then |
252 |
warn "Error: you must provide at least one instance name" |
253 |
fi |
254 |
fi |
255 |
|
256 |
exit 0 |