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

(-)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 (+256 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
    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
(-)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
        C4::Context->clear_syspref_cache();
46
        return $q;
47
    };
48
}
49
50
my $intranet = Plack::App::CGIBin->new(
51
    root => '/usr/share/koha/intranet/cgi-bin'
52
);
53
54
my $opac = Plack::App::CGIBin->new(
55
    root => '/usr/share/koha/opac/cgi-bin/opac'
56
);
57
58
# my $api  = Plack::App::CGIBin->new(
59
#     root => '/usr/share/koha/api/'
60
# );
61
62
builder {
63
64
    enable "ReverseProxy";
65
    enable "Plack::Middleware::Static";
66
67
    mount '/opac'     => $opac;
68
    mount '/intranet' => $intranet;
69
    # mount '/api'       => $api;
70
};
71

Return to bug 13791