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

(-)a/debian/koha-common.install (+1 lines)
Lines 20-25 debian/scripts/koha-foreach usr/sbin Link Here
20
debian/scripts/koha-indexer                 usr/sbin
20
debian/scripts/koha-indexer                 usr/sbin
21
debian/scripts/koha-list                    usr/sbin
21
debian/scripts/koha-list                    usr/sbin
22
debian/scripts/koha-mysql                   usr/sbin
22
debian/scripts/koha-mysql                   usr/sbin
23
debian/scripts/koha-plack                   usr/sbin
23
debian/scripts/koha-rebuild-zebra           usr/sbin
24
debian/scripts/koha-rebuild-zebra           usr/sbin
24
debian/scripts/koha-remove                  usr/sbin
25
debian/scripts/koha-remove                  usr/sbin
25
debian/scripts/koha-reset-passwd            usr/sbin
26
debian/scripts/koha-reset-passwd            usr/sbin
(-)a/debian/scripts/koha-functions.sh (+31 lines)
Lines 121-126 is_indexer_running() Link Here
121
    fi
121
    fi
122
}
122
}
123
123
124
is_plack_enabled()
125
{
126
    local site=$1
127
    local instancefile=$(get_apache_config_for $site)
128
129
    if [ "$instancefile" = "" ]; then
130
        return 1
131
    fi
132
133
    if grep -q '^[[:space:]]*Include /etc/koha/apache-shared-opac-plack.conf' \
134
            "$instancefile" && \
135
       grep -q '^[[:space:]]*Include /etc/koha/apache-shared-intranet-plack.conf' \
136
            "$instancefile" ; then
137
        return 1
138
    else
139
        return 0
140
    fi
141
}
142
143
is_plack_running()
144
{
145
    local instancename=$1
146
147
    if start-stop-daemon --pidfile "/var/run/koha/${instancename}/plack.pid" \
148
            --status ; then
149
        return 0
150
    else
151
        return 1
152
    fi
153
}
154
124
get_instances()
155
get_instances()
125
{
156
{
126
    find /etc/koha/sites -mindepth 1 -maxdepth 1\
157
    find /etc/koha/sites -mindepth 1 -maxdepth 1\
(-)a/debian/scripts/koha-plack (+302 lines)
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
    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
74
75
    STARMANOPTS="-M FindBin --max-requests 50 --workers 2 \
76
                 --user=${instancename}-koha --group ${instancename}-koha \
77
                 --pid ${PIDFILE} \
78
                 --daemonize \
79
                 --access-log /var/log/koha/${instancename}/plack.log \
80
                 --error-log /var/log/koha/${instancename}/plack-error.log \
81
                 -E deployment --socket ${PLACKSOCKET} ${PSGIFILE}"
82
83
    if ! is_plack_running ${instancename}; then
84
        export KOHA_CONF="/etc/koha/sites/${instancename}/koha-conf.xml"
85
86
        log_daemon_msg "Starting Plack daemon for ${instancename}"
87
88
        if ${STARMAN} ${STARMANOPTS}; then
89
            log_end_msg 0
90
        else
91
            log_end_msg 1
92
        fi
93
    else
94
        log_daemon_msg "Error: Plack already running for ${instancename}"
95
        log_end_msg 1
96
    fi
97
}
98
99
stop_plack()
100
{
101
    local instancename=$1
102
103
    local PIDFILE="/var/run/koha/${instancename}/plack.pid"
104
105
    if is_plack_running ${instancename}; then
106
107
        log_daemon_msg "Stopping Plack daemon for ${instancename}"
108
109
        if start-stop-daemon --pidfile ${PIDFILE} --stop; then
110
            log_end_msg 0
111
        else
112
            log_end_msg 1
113
        fi
114
    else
115
        log_daemon_msg "Error: Plack not running for ${instancename}"
116
        log_end_msg 1
117
    fi
118
}
119
120
restart_plack()
121
{
122
    local instancename=$1
123
124
    local PIDFILE="/var/run/koha/${instancename}/plack.pid"
125
126
    if is_plack_running ${instancename}; then
127
128
        log_daemon_msg "Restarting Plack daemon for ${instancename}"
129
130
        if stop_plack $instancename && start_plack $instancename; then
131
            log_end_msg 0
132
        else
133
            log_end_msg 1
134
        fi
135
    else
136
        log_daemon_msg "Error: Plack not running for ${instancename}"
137
        log_end_msg 1
138
    fi
139
}
140
141
enable_plack()
142
{
143
    local instancename=$1
144
    local instancefile=$(get_apache_config_for "$instancename")
145
146
    if ! is_plack_enabled $instancename; then
147
        # Uncomment the plack related lines for OPAC and intranet
148
        sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:\1:' "$instancefile"
149
        sed -i 's:^\s*#\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:\1:' "$instancefile"
150
        [ "${quiet}" != "yes" ] && warn "Plack enabled for ${instancename}"
151
        return 0
152
    else
153
        [ "${quiet}" != "yes" ] && warn "Plack already enabled for ${instancename}"
154
        return 1
155
    fi
156
}
157
158
disable_plack()
159
{
160
    local instancename=$1
161
    local instancefile=$(get_apache_config_for "$instancename")
162
163
    if is_plack_enabled $instancename; then
164
        # Comment out the plack related lines for OPAC and intranet
165
        sed -i 's:^\(\s*Include /etc/koha/apache-shared-opac-plack.conf\)$:#\1:' "$instancefile"
166
        sed -i 's:^\(\s*Include /etc/koha/apache-shared-intranet-plack.conf\)$:#\1:' "$instancefile"
167
        [ "${quiet}" != "yes" ] && warn "Plack disabled for ${instancename}"
168
        return 0
169
    else
170
        [ "${quiet}" != "yes" ] && warn "Plack already disabled for ${instancename}"
171
        return 1
172
    fi
173
}
174
175
check_env_and_warn()
176
{
177
    local apache_version_ok="no"
178
    local required_modules="headers proxy_http"
179
    local missing_modules=""
180
181
    if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
182
        apache_version_ok="yes"
183
    fi
184
185
    for module in ${required_modules}; do
186
        if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q ${module}; then
187
            missing_modules="${missing_modules}${module} "
188
        fi
189
    done
190
191
    if [ "${apache_version_ok}" != "yes" ]; then
192
        warn "WARNING: koha-plack requires Apache 2.4.x and you don't have that."
193
    fi
194
195
    if [ "${missing_modules}" != "" ]; then
196
        cat 1>&2 <<EOM
197
WARNING: koha-plack requires some Apache modules that you are missing.
198
You can install them with:
199
200
    sudo a2enmod ${missing_modules}
201
202
EOM
203
204
    fi
205
}
206
207
set_action()
208
{
209
    if [ "$op" = "" ]; then
210
        op=$1
211
    else
212
        die "Error: only one action can be specified."
213
    fi
214
}
215
216
STARMAN=$(which starman)
217
op=""
218
quiet="no"
219
220
# Read command line parameters
221
while [ $# -gt 0 ]; do
222
223
    case "$1" in
224
        -h|--help)
225
            usage ; exit 0 ;;
226
        -q|--quiet)
227
            quiet="yes"
228
            shift ;;
229
        --start)
230
            set_action "start"
231
            shift ;;
232
        --stop)
233
            set_action "stop"
234
            shift ;;
235
        --restart)
236
            set_action "restart"
237
            shift ;;
238
        --enable)
239
            set_action "enable"
240
            shift ;;
241
        --disable)
242
            set_action "disable"
243
            shift ;;
244
        -*)
245
            die "Error: invalid option switch ($1)" ;;
246
        *)
247
            # We expect the remaining stuff are the instance names
248
            break ;;
249
    esac
250
251
done
252
253
if [ -z $PERL5LIB ]; then
254
    PERL5LIB="/usr/share/koha/lib"
255
fi
256
257
export PERL5LIB
258
259
[ "${quiet}" != "yes" ] && check_env_and_warn
260
261
if [ $# -gt 0 ]; then
262
    # We have at least one instance name
263
    for name in "$@"; do
264
265
        if is_instance $name; then
266
267
            case $op in
268
                "start")
269
                    start_plack $name
270
                    ;;
271
                "stop")
272
                    stop_plack $name
273
                    ;;
274
                "restart")
275
                    restart_plack $name
276
                    ;;
277
                "enable")
278
                    enable_plack $name
279
                    ;;
280
                "disable")
281
                    disable_plack $name
282
                    ;;
283
                *)
284
                    usage
285
                    ;;
286
            esac
287
288
        else
289
            if [ "$quiet" = "no" ]; then
290
                log_daemon_msg "Error: Invalid instance name $name"
291
                log_end_msg 1
292
            fi
293
        fi
294
295
    done
296
else
297
    if [ "$quiet" = "no" ]; then
298
        warn "Error: you must provide at least one instance name"
299
    fi
300
fi
301
302
exit 0
(-)a/debian/templates/plack.psgi (-1 / +71 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
use lib("/usr/share/koha/lib");
19
use lib("/usr/share/koha/lib/installer");
20
21
use Plack::Builder;
22
use Plack::App::CGIBin;
23
use Plack::App::Directory;
24
use Plack::App::URLMap;
25
26
# Pre-load libraries
27
use C4::Boolean;
28
use C4::Branch;
29
use C4::Category;
30
use C4::Dates;
31
use C4::Koha;
32
use C4::Languages;
33
use C4::Letters;
34
use C4::Members;
35
use C4::XSLT;
36
use Koha::Database;
37
38
use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise
39
{
40
    no warnings 'redefine';
41
    my $old_new = \&CGI::new;
42
    *CGI::new = sub {
43
        my $q = $old_new->( @_ );
44
        $CGI::PARAM_UTF8 = 1;
45
        return $q;
46
    };
47
}
48
49
C4::Context->disable_syspref_cache();
50
51
my $intranet = Plack::App::CGIBin->new(
52
    root => '/usr/share/koha/intranet/cgi-bin'
53
);
54
55
my $opac = Plack::App::CGIBin->new(
56
    root => '/usr/share/koha/opac/cgi-bin/opac'
57
);
58
59
# my $api  = Plack::App::CGIBin->new(
60
#     root => '/usr/share/koha/api/'
61
# );
62
63
builder {
64
65
    enable "ReverseProxy";
66
    enable "Plack::Middleware::Static";
67
68
    mount '/opac'     => $opac;
69
    mount '/intranet' => $intranet;
70
    # mount '/api'       => $api;
71
};

Return to bug 13791