3 # Copyright 2015 Theke Solutions
5 # This file is part of Koha.
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.
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.
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/>.
22 . /lib/lsb/init-functions
24 # Read configuration variable file if it is present
25 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
27 # include helper functions
28 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
29 . "/usr/share/koha/bin/koha-functions.sh"
31 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
37 local scriptname=$(basename $0)
42 This script lets you manage the plack daemons for your Koha instances.
45 $scriptname --start|--stop|--restart [--quiet|-q] instancename1 [instancename2...]
46 $scriptname --enable|--disable instancename1 [instancename2]
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
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"
70 if [ -e "/etc/koha/sites/${instancename}/plack.psgi" ]; then
71 # pick instance-specific psgi file
72 PSGIFILE="/etc/koha/sites/${instancename}/plack.psgi"
73 fi # else stick with the default one
75 _check_and_fix_perms $instancename
77 PLACK_MAX_REQUESTS=$(run_safe_xmlstarlet $instancename plack_max_requests)
78 [ -z $PLACK_MAX_REQUESTS ] && PLACK_MAX_REQUESTS="50"
79 PLACK_WORKERS=$(run_safe_xmlstarlet $instancename plack_workers)
80 [ -z $PLACK_WORKERS ] && PLACK_WORKERS="2"
82 STARMANOPTS="-M FindBin --max-requests ${PLACK_MAX_REQUESTS} --workers ${PLACK_WORKERS} \
83 --user=${instancename}-koha --group ${instancename}-koha \
86 --access-log /var/log/koha/${instancename}/plack.log \
87 --error-log /var/log/koha/${instancename}/plack-error.log \
88 -E deployment --socket ${PLACKSOCKET} ${PSGIFILE}"
90 if ! is_plack_running ${instancename}; then
91 export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml"
92 export MEMCACHED_SERVERS=$(get_memcached_servers_for $instancename)
93 export MEMCACHED_NAMESPACE=$(get_memcached_namespace_for $instancename)
95 log_daemon_msg "Starting Plack daemon for ${instancename}"
97 if ${STARMAN} ${STARMANOPTS}; then
103 log_daemon_msg "Error: Plack already running for ${instancename}"
110 local instancename=$1
112 local PIDFILE="/var/run/koha/${instancename}/plack.pid"
114 if is_plack_running ${instancename}; then
116 log_daemon_msg "Stopping Plack daemon for ${instancename}"
118 if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then
124 log_daemon_msg "Error: Plack not running for ${instancename}"
131 local instancename=$1
133 local PIDFILE="/var/run/koha/${instancename}/plack.pid"
135 if is_plack_running ${instancename}; then
137 log_daemon_msg "Restarting Plack daemon for ${instancename}"
139 if stop_plack $instancename && start_plack $instancename; then
145 log_daemon_msg "Error: Plack not running for ${instancename}"
152 local instancename=$1
153 local instancefile=$(get_apache_config_for "$instancename")
155 if ! is_plack_enabled $instancename; then
156 # Uncomment the plack related lines for OPAC and intranet
157 sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:\1:' "$instancefile"
158 sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:\1:' "$instancefile"
159 [ "${quiet}" != "yes" ] && warn "Plack enabled for ${instancename}"
162 [ "${quiet}" != "yes" ] && warn "Plack already enabled for ${instancename}"
169 local instancename=$1
170 local instancefile=$(get_apache_config_for "$instancename")
172 if is_plack_enabled $instancename; then
173 # Comment out the plack related lines for OPAC and intranet
174 sed -i 's:^\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:#\1:' "$instancefile"
175 sed -i 's:^\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:#\1:' "$instancefile"
176 [ "${quiet}" != "yes" ] && warn "Plack disabled for ${instancename}"
179 [ "${quiet}" != "yes" ] && warn "Plack already disabled for ${instancename}"
186 local apache_version_ok="no"
187 local required_modules="headers proxy_http"
188 local missing_modules=""
190 if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
191 apache_version_ok="yes"
194 for module in ${required_modules}; do
195 if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q ${module}; then
196 missing_modules="${missing_modules}${module} "
200 if [ "${apache_version_ok}" != "yes" ]; then
201 warn "WARNING: koha-plack requires Apache 2.4.x and you don't have that."
204 if [ "${missing_modules}" != "" ]; then
206 WARNING: koha-plack requires some Apache modules that you are missing.
207 You can install them with:
209 sudo a2enmod ${missing_modules}
216 _check_and_fix_perms()
220 local files="/var/log/koha/${instance}/plack.log \
221 /var/log/koha/${instance}/plack-error.log"
225 if [ ! -e "${file}" ]; then
228 chown "${instance}-koha":"${instance}-koha" ${file}
234 if [ "$op" = "" ]; then
237 die "Error: only one action can be specified."
241 STARMAN=$(which starman)
245 # Read command line parameters
246 while [ $# -gt 0 ]; do
270 die "Error: invalid option switch ($1)" ;;
272 # We expect the remaining stuff are the instance names
278 if [ -z $PERL5LIB ]; then
279 PERL5LIB="/usr/share/koha/lib"
284 [ "${quiet}" != "yes" ] && check_env_and_warn
286 if [ $# -gt 0 ]; then
287 # We have at least one instance name
290 if is_instance $name; then
314 if [ "$quiet" = "no" ]; then
315 log_daemon_msg "Error: Invalid instance name $name"
322 if [ "$quiet" = "no" ]; then
323 warn "Error: you must provide at least one instance name"