mise au point plack
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
- proxy
|
||||
- proxy_http
|
||||
- ssl
|
||||
- headers
|
||||
- cgi
|
||||
notify: reload apache
|
||||
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
- name: create plack dir
|
||||
file:
|
||||
path: "{{ koha_install_dir }}/bin/plack"
|
||||
state: directory
|
||||
owner: koha
|
||||
group: koha
|
||||
|
||||
- name: deploy plack script
|
||||
template:
|
||||
src: koha-plack
|
||||
dest: "{{ koha_install_dir }}/bin/plack"
|
||||
owner: koha
|
||||
group: koha
|
||||
mode: 0750
|
||||
|
||||
- name: deploy plack service
|
||||
template:
|
||||
src: plack-opac.service
|
||||
src: plack.service
|
||||
dest: /etc/systemd/system/
|
||||
notify: reload systemd
|
||||
|
||||
- name: start and activate plack service
|
||||
systemd:
|
||||
name: plack-opac.service
|
||||
name: plack.service
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
|
||||
278
templates/koha-plack
Executable file
278
templates/koha-plack
Executable file
@@ -0,0 +1,278 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2015 Theke Solutions
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set -e
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
export PERL5LIB={{ koha_install_dir }}/lib
|
||||
|
||||
usage()
|
||||
{
|
||||
local scriptname=$(basename $0)
|
||||
|
||||
cat <<EOF
|
||||
$scriptname
|
||||
|
||||
This script lets you manage the plack daemons for your Koha instances.
|
||||
|
||||
Usage:
|
||||
$scriptname --start|--stop|--restart [--quiet|-q] instancename1 [instancename2...]
|
||||
$scriptname --enable|--disable instancename1 [instancename2]
|
||||
$scriptname -h|--help
|
||||
|
||||
--start Start the plack daemon for the specified instances
|
||||
--stop Stop the plack daemon for the specified instances
|
||||
--restart Restart the plack daemon for the specified instances
|
||||
--quiet|-q Make the script quiet about non existent instance names
|
||||
(useful for calling from another scripts).
|
||||
--help|-h Display this help message
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
start_plack()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
local PIDFILE="{{ koha_install_dir }}/var/run/plack.pid"
|
||||
local PLACKSOCKET="{{ koha_install_dir }}/var/run/plack.sock"
|
||||
local PSGIFILE="{{ koha_install_dir }}/bin/plack/koha.psgi"
|
||||
local NAME="${instancename}-koha-plack"
|
||||
|
||||
if [ -e "/etc/koha/plack.psgi" ]; then
|
||||
# pick instance-specific psgi file
|
||||
PSGIFILE="/etc/koha/plack.psgi"
|
||||
fi # else stick with the default one
|
||||
|
||||
_check_and_fix_perms $instancename
|
||||
|
||||
STARMANOPTS="-M FindBin --max-requests 50 --workers 8 \
|
||||
--user=www-data --group www-data \
|
||||
--pid ${PIDFILE} \
|
||||
--daemonize \
|
||||
--access-log /var/log/koha/plack.log \
|
||||
--error-log /var/log/koha/plack-error.log \
|
||||
-E deployment --socket ${PLACKSOCKET} ${PSGIFILE}"
|
||||
|
||||
if ! is_plack_running ${instancename}; then
|
||||
export KOHA_CONF="{{ koha_install_dir }}/etc/koha-conf.xml"
|
||||
if [ -e "/etc/koha/koha-conf.xml" ]; then
|
||||
# pick instance-specific psgi file
|
||||
KOHA_CONF="/etc/koha/koha-conf.xml"
|
||||
fi # else stick with the default one
|
||||
|
||||
log_daemon_msg "Starting Plack daemon for ${instancename}"
|
||||
|
||||
if ${STARMAN} ${STARMANOPTS}; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
else
|
||||
log_daemon_msg "Error: Plack already running for ${instancename}"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
stop_plack()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
local PIDFILE="{{ koha_install_dir }}/var/run/plack.pid"
|
||||
|
||||
if is_plack_running ${instancename}; then
|
||||
|
||||
log_daemon_msg "Stopping Plack daemon for ${instancename}"
|
||||
|
||||
if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then
|
||||
rm -f ${PIDFILE}
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
else
|
||||
log_daemon_msg "Error: Plack not running for ${instancename}"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
restart_plack()
|
||||
{
|
||||
local instancename=$1
|
||||
local PIDFILE="{{ koha_install_dir }}/var/run/plack.pid"
|
||||
|
||||
if is_plack_running ${instancename}; then
|
||||
|
||||
log_daemon_msg "Restarting Plack daemon for ${instancename}"
|
||||
|
||||
if stop_plack $instancename && start_plack $instancename; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
else
|
||||
log_daemon_msg "Error: Plack not running for ${instancename}"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_env_and_warn()
|
||||
{
|
||||
local apache_version_ok="no"
|
||||
local required_modules="headers proxy_http"
|
||||
local missing_modules=""
|
||||
|
||||
if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
|
||||
apache_version_ok="yes"
|
||||
fi
|
||||
|
||||
for module in ${required_modules}; do
|
||||
if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q ${module}; then
|
||||
missing_modules="${missing_modules}${module} "
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${apache_version_ok}" != "yes" ]; then
|
||||
echo "WARNING: koha-plack requires Apache 2.4.x and you don't have that."
|
||||
fi
|
||||
|
||||
if [ "${missing_modules}" != "" ]; then
|
||||
cat 1>&2 <<EOM
|
||||
WARNING: koha-plack requires some Apache modules that you are missing.
|
||||
You can install them with:
|
||||
|
||||
sudo a2enmod ${missing_modules}
|
||||
|
||||
EOM
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
_check_and_fix_perms()
|
||||
{
|
||||
local instance=$1
|
||||
|
||||
local files="/var/log/koha/plack.log \
|
||||
/var/log/koha/plack-error.log"
|
||||
|
||||
for file in ${files}
|
||||
do
|
||||
if [ ! -e "${file}" ]; then
|
||||
touch ${file}
|
||||
fi
|
||||
chown "koha":"koha" ${file}
|
||||
done
|
||||
}
|
||||
|
||||
set_action()
|
||||
{
|
||||
if [ "$op" = "" ]; then
|
||||
op=$1
|
||||
else
|
||||
echo "Error: only one action can be specified." ; exit 1 ;
|
||||
fi
|
||||
}
|
||||
|
||||
#################Functions from koha_functions.sh##################
|
||||
|
||||
is_plack_running()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
if start-stop-daemon --pidfile "{{ koha_install_dir }}/var/run/plack.pid" \
|
||||
--status ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
###################################################################
|
||||
|
||||
STARMAN=$(which starman)
|
||||
op=""
|
||||
quiet="no"
|
||||
|
||||
# Read command line parameters
|
||||
while [ $# -gt 0 ]; do
|
||||
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
usage ; exit 0 ;;
|
||||
-q|--quiet)
|
||||
quiet="yes"
|
||||
shift ;;
|
||||
--start)
|
||||
set_action "start"
|
||||
shift ;;
|
||||
--stop)
|
||||
set_action "stop"
|
||||
shift ;;
|
||||
--restart)
|
||||
set_action "restart"
|
||||
shift ;;
|
||||
--enable)
|
||||
set_action "enable"
|
||||
shift ;;
|
||||
--disable)
|
||||
set_action "disable"
|
||||
shift ;;
|
||||
-*)
|
||||
echo "Error: invalid option switch ($1)" ; exit 5 ;;
|
||||
*)
|
||||
# We expect the remaining stuff are the instance names
|
||||
break ;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
if [ -z $PERL5LIB ]; then
|
||||
PERL5LIB="/usr/share/koha/lib"
|
||||
fi
|
||||
|
||||
export PERL5LIB
|
||||
|
||||
[ "${quiet}" != "yes" ] && check_env_and_warn
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
# We have at least one instance name
|
||||
for name in "$@"; do
|
||||
case $op in
|
||||
"start")
|
||||
start_plack $name
|
||||
;;
|
||||
"stop")
|
||||
stop_plack $name
|
||||
;;
|
||||
"restart")
|
||||
restart_plack $name
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
if [ "$quiet" = "no" ]; then
|
||||
echo "Error: you must provide at least one instance name"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,11 +0,0 @@
|
||||
[Unit]
|
||||
Description=plack pour opac
|
||||
After=network.target remote-fs.target nss-lookup.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStart={{ koha_install_dir }}/bin/plack/plackup.sh foo
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
14
templates/plack.service
Normal file
14
templates/plack.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=plack pour opac
|
||||
After=network.target remote-fs.target nss-lookup.target
|
||||
|
||||
[Service]
|
||||
Environment="KOHA_CONF={{ koha_install_dir }}/etc/koha-conf.xml"
|
||||
Environment="PERL5LIB={{ koha_install_dir }}/lib"
|
||||
Type=forking
|
||||
User=root
|
||||
ExecStart={{ koha_install_dir }}/bin/plack/koha-plack --start foobar
|
||||
ExecStop={{ koha_install_dir }}/bin/plack/koha-plack --stop foobar
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
42
templates/plack/README.plack
Normal file
42
templates/plack/README.plack
Normal file
@@ -0,0 +1,42 @@
|
||||
Bug 7844 - plack intranet tooling for developers
|
||||
|
||||
koha.psgi example and plackup.sh script to run any Koha site
|
||||
intranet or opac interface under plack with optional multi-process
|
||||
Starman server
|
||||
|
||||
plackup.sh site-name [intranet]
|
||||
|
||||
site-name is used to find config /etc/koha/sites/site-name/koha-conf.xml
|
||||
|
||||
All configuration is specified in koha.psgi, which you are welcomed to edit
|
||||
and tune according to your development needs (enable memcache, enable/disable
|
||||
debugging modules for plack and so on).
|
||||
|
||||
For deployment of opac or intranet you would probably want to take a look
|
||||
in plackup.sh and enable starman as web server (which is pre-forking server
|
||||
written in perl) and put some web server in front of it to serve static web
|
||||
files (e.g. ngnix, apache)
|
||||
|
||||
When you are happy with it, rename koha.psgi and plackup.sh it to site name
|
||||
and save it for safe-keeping.
|
||||
|
||||
This commit message is included in patch as README.plack because it includes
|
||||
useful information for people using plack for first time.
|
||||
|
||||
Test scenario:
|
||||
1. install plack and dependencies, as documented at
|
||||
http://wiki.koha-community.org/wiki/Plack
|
||||
|
||||
2. start ./plackup.sh sitename i[ntranet]
|
||||
|
||||
3. open intranet page http://localhost:5001/ and verify that it redirects
|
||||
to http://localhost:5001/cgi-bin/koha/mainpage.pl
|
||||
|
||||
4. start ./plackup.sh sitename
|
||||
|
||||
5. open OPAC http://localhost:5000/ and verify that it redirects to
|
||||
http://localhost:5000/cgi-bin/koha/opac-main.pl
|
||||
|
||||
6. next step is to take a look into koha.psgi and enable additional
|
||||
debug modules, save file and reload page (plackup will reload
|
||||
code automatically)
|
||||
277
templates/plack/koha-plack.debug
Executable file
277
templates/plack/koha-plack.debug
Executable file
@@ -0,0 +1,277 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2015 Theke Solutions
|
||||
#
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set -e
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
# Read configuration variable file if it is present
|
||||
[ -r /etc/default/koha-common ] && . /etc/default/koha-common
|
||||
export PERL5LIB=/home/koha/koha/lib
|
||||
|
||||
usage()
|
||||
{
|
||||
local scriptname=$(basename $0)
|
||||
|
||||
cat <<EOF
|
||||
$scriptname
|
||||
|
||||
This script lets you manage the plack daemons for your Koha instances.
|
||||
|
||||
Usage:
|
||||
$scriptname --start|--stop|--restart [--quiet|-q] instancename1 [instancename2...]
|
||||
$scriptname --enable|--disable instancename1 [instancename2]
|
||||
$scriptname -h|--help
|
||||
|
||||
--start Start the plack daemon for the specified instances
|
||||
--stop Stop the plack daemon for the specified instances
|
||||
--restart Restart the plack daemon for the specified instances
|
||||
--quiet|-q Make the script quiet about non existent instance names
|
||||
(useful for calling from another scripts).
|
||||
--help|-h Display this help message
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
start_plack()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
local PIDFILE="/home/koha/koha/var/run/plack.pid"
|
||||
local PLACKSOCKET="/home/koha/koha/var/run/plack.sock"
|
||||
local PSGIFILE="/home/koha/koha/bin/plack/koha.psgi"
|
||||
local NAME="${instancename}-koha-plack"
|
||||
|
||||
if [ -e "/etc/koha/plack.psgi" ]; then
|
||||
# pick instance-specific psgi file
|
||||
PSGIFILE="/etc/koha/plack.psgi"
|
||||
fi # else stick with the default one
|
||||
|
||||
_check_and_fix_perms $instancename
|
||||
|
||||
STARMANOPTS="-M FindBin --max-requests 50 --workers 8 \
|
||||
--user=www-data --group www-data \
|
||||
--pid ${PIDFILE} \
|
||||
-E deployment --socket ${PLACKSOCKET} ${PSGIFILE}"
|
||||
|
||||
if ! is_plack_running ${instancename}; then
|
||||
export KOHA_CONF="/home/koha/koha/etc/koha-conf.xml"
|
||||
if [ -e "/etc/koha/koha-conf.xml" ]; then
|
||||
# pick instance-specific psgi file
|
||||
KOHA_CONF="/etc/koha/koha-conf.xml"
|
||||
fi # else stick with the default one
|
||||
|
||||
log_daemon_msg "Starting Plack daemon for ${instancename}"
|
||||
|
||||
if ${STARMAN} ${STARMANOPTS}; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
else
|
||||
log_daemon_msg "Error: Plack already running for ${instancename}"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
stop_plack()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
local PIDFILE="/home/koha/koha/var/run/plack.pid"
|
||||
|
||||
if is_plack_running ${instancename}; then
|
||||
|
||||
log_daemon_msg "Stopping Plack daemon for ${instancename}"
|
||||
|
||||
if start-stop-daemon --pidfile ${PIDFILE} --stop --retry=TERM/30/KILL/5; then
|
||||
rm -f ${PIDFILE}
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
else
|
||||
log_daemon_msg "Error: Plack not running for ${instancename}"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
restart_plack()
|
||||
{
|
||||
local instancename=$1
|
||||
local PIDFILE="/home/koha/koha/var/run/plack.pid"
|
||||
|
||||
if is_plack_running ${instancename}; then
|
||||
|
||||
log_daemon_msg "Restarting Plack daemon for ${instancename}"
|
||||
|
||||
if stop_plack $instancename && start_plack $instancename; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
else
|
||||
log_daemon_msg "Error: Plack not running for ${instancename}"
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_env_and_warn()
|
||||
{
|
||||
local apache_version_ok="no"
|
||||
local required_modules="headers proxy_http"
|
||||
local missing_modules=""
|
||||
|
||||
if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
|
||||
apache_version_ok="yes"
|
||||
fi
|
||||
|
||||
for module in ${required_modules}; do
|
||||
if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q ${module}; then
|
||||
missing_modules="${missing_modules}${module} "
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${apache_version_ok}" != "yes" ]; then
|
||||
echo "WARNING: koha-plack requires Apache 2.4.x and you don't have that."
|
||||
fi
|
||||
|
||||
if [ "${missing_modules}" != "" ]; then
|
||||
cat 1>&2 <<EOM
|
||||
WARNING: koha-plack requires some Apache modules that you are missing.
|
||||
You can install them with:
|
||||
|
||||
sudo a2enmod ${missing_modules}
|
||||
|
||||
EOM
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
_check_and_fix_perms()
|
||||
{
|
||||
local instance=$1
|
||||
|
||||
local files="/var/log/koha/plack.log \
|
||||
/var/log/koha/plack-error.log"
|
||||
|
||||
for file in ${files}
|
||||
do
|
||||
if [ ! -e "${file}" ]; then
|
||||
touch ${file}
|
||||
fi
|
||||
chown "koha":"koha" ${file}
|
||||
done
|
||||
}
|
||||
|
||||
set_action()
|
||||
{
|
||||
if [ "$op" = "" ]; then
|
||||
op=$1
|
||||
else
|
||||
echo "Error: only one action can be specified." ; exit 1 ;
|
||||
fi
|
||||
}
|
||||
|
||||
#################Functions from koha_functions.sh##################
|
||||
|
||||
is_plack_running()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
if start-stop-daemon --pidfile "/home/koha/koha/var/run/plack.pid" \
|
||||
--status ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
###################################################################
|
||||
|
||||
STARMAN=$(which starman)
|
||||
op=""
|
||||
quiet="no"
|
||||
|
||||
# Read command line parameters
|
||||
while [ $# -gt 0 ]; do
|
||||
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
usage ; exit 0 ;;
|
||||
-q|--quiet)
|
||||
quiet="yes"
|
||||
shift ;;
|
||||
--start)
|
||||
set_action "start"
|
||||
shift ;;
|
||||
--stop)
|
||||
set_action "stop"
|
||||
shift ;;
|
||||
--restart)
|
||||
set_action "restart"
|
||||
shift ;;
|
||||
--enable)
|
||||
set_action "enable"
|
||||
shift ;;
|
||||
--disable)
|
||||
set_action "disable"
|
||||
shift ;;
|
||||
-*)
|
||||
echo "Error: invalid option switch ($1)" ; exit 5 ;;
|
||||
*)
|
||||
# We expect the remaining stuff are the instance names
|
||||
break ;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
if [ -z $PERL5LIB ]; then
|
||||
PERL5LIB="/usr/share/koha/lib"
|
||||
fi
|
||||
|
||||
export PERL5LIB
|
||||
|
||||
[ "${quiet}" != "yes" ] && check_env_and_warn
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
# We have at least one instance name
|
||||
for name in "$@"; do
|
||||
case $op in
|
||||
"start")
|
||||
start_plack $name
|
||||
;;
|
||||
"stop")
|
||||
stop_plack $name
|
||||
;;
|
||||
"restart")
|
||||
restart_plack $name
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
if [ "$quiet" = "no" ]; then
|
||||
echo "Error: you must provide at least one instance name"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
140
templates/plack/koha-plack.sh
Executable file
140
templates/plack/koha-plack.sh
Executable file
@@ -0,0 +1,140 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: koha-plack
|
||||
# Required-Start: $remote_fs
|
||||
# Required-Stop: $remote_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start starman server for Koha plack
|
||||
# Description: For each enabled Koha instance on this host,
|
||||
# start a starman server for using plack
|
||||
### END INIT INFO
|
||||
|
||||
# Author: Baptiste Costes
|
||||
|
||||
# Do NOT "set -e"
|
||||
|
||||
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="Koha Plack"
|
||||
NAME="koha-plack"
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x /usr/sbin/koha-plack ] || exit 0
|
||||
|
||||
# Read configuration variable file if it is present
|
||||
if [ -r /etc/default/$NAME ]; then
|
||||
# Debian / Ubuntu
|
||||
. /etc/default/$NAME
|
||||
elif [ -r /etc/sysconfig/$NAME ]; then
|
||||
# RedHat / SuSE
|
||||
. /etc/sysconfig/$NAME
|
||||
fi
|
||||
|
||||
# Load the VERBOSE setting and other rcS variables
|
||||
. /lib/init/vars.sh
|
||||
|
||||
# Define LSB log_* functions.
|
||||
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
#
|
||||
do_start()
|
||||
{
|
||||
# We insure all required directories exist, including disabled ones.
|
||||
koha-plack --start koha
|
||||
}
|
||||
|
||||
#
|
||||
# Function that stops the daemon/service
|
||||
#
|
||||
do_stop()
|
||||
{
|
||||
koha-plack --stop --quiet koha
|
||||
}
|
||||
|
||||
#
|
||||
# Function that sends a SIGHUP to the daemon/service
|
||||
#
|
||||
do_reload() {
|
||||
koha-plack --restart --quiet koha
|
||||
}
|
||||
|
||||
#
|
||||
# Function that shows the status of the Plack server daemon for
|
||||
# enabled instances
|
||||
#
|
||||
plack_status()
|
||||
{
|
||||
log_daemon_msg "Plack server running for instance koha"
|
||||
|
||||
if is_plack_running "koha" ; then
|
||||
log_end_msg 0
|
||||
else
|
||||
log_end_msg 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_plack_running()
|
||||
{
|
||||
local instancename=$1
|
||||
|
||||
if start-stop-daemon --pidfile "/var/run/koha/plack.pid" \
|
||||
--status ; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
||||
do_start
|
||||
case "$?" in
|
||||
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
*) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
*) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
restart|force-reload)
|
||||
#
|
||||
# If the "reload" option is implemented then remove the
|
||||
# 'force-reload' alias
|
||||
#
|
||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0)
|
||||
do_start
|
||||
case "$?" in
|
||||
0) log_end_msg 0 ;;
|
||||
*) log_end_msg 1 ;; # Failed to start
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
# Failed to stop
|
||||
log_end_msg 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
status)
|
||||
plack_status
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
:
|
||||
80
templates/plack/koha.psgi
Normal file
80
templates/plack/koha.psgi
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
use lib("/home/koha/koha/lib");
|
||||
use lib("/home/koha/koha/lib/installer");
|
||||
|
||||
use Plack::Builder;
|
||||
use Plack::App::CGIBin;
|
||||
use Plack::App::Directory;
|
||||
use Plack::App::URLMap;
|
||||
use Plack::Request;
|
||||
|
||||
use Mojo::Server::PSGI;
|
||||
|
||||
# Pre-load libraries
|
||||
use C4::Boolean;
|
||||
use C4::Koha;
|
||||
use C4::Languages;
|
||||
use C4::Letters;
|
||||
use C4::Members;
|
||||
use C4::XSLT;
|
||||
use Koha::Caches;
|
||||
use Koha::Cache::Memory::Lite;
|
||||
use Koha::Database;
|
||||
use Koha::DateUtils;
|
||||
|
||||
use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise
|
||||
{
|
||||
no warnings 'redefine';
|
||||
my $old_new = \&CGI::new;
|
||||
*CGI::new = sub {
|
||||
my $q = $old_new->( @_ );
|
||||
$CGI::PARAM_UTF8 = 1;
|
||||
Koha::Caches->flush_L1_caches();
|
||||
Koha::Cache::Memory::Lite->flush();
|
||||
return $q;
|
||||
};
|
||||
}
|
||||
|
||||
my $intranet = Plack::App::CGIBin->new(
|
||||
root => '/home/koha/koha/intranet/cgi-bin'
|
||||
)->to_app;
|
||||
|
||||
my $opac = Plack::App::CGIBin->new(
|
||||
root => '/home/koha/koha/opac/cgi-bin/opac'
|
||||
)->to_app;
|
||||
|
||||
my $apiv1 = builder {
|
||||
my $server = Mojo::Server::PSGI->new;
|
||||
$server->load_app('/home/koha/koha/api/v1/app.pl');
|
||||
$server->to_psgi_app;
|
||||
};
|
||||
|
||||
builder {
|
||||
enable "ReverseProxy";
|
||||
enable "Plack::Middleware::Static";
|
||||
# + is required so Plack doesn't try to prefix Plack::Middleware::
|
||||
enable "+Koha::Middleware::SetEnv";
|
||||
|
||||
mount '/opac' => $opac;
|
||||
mount '/intranet' => $intranet;
|
||||
mount '/api/v1/app.pl' => $apiv1;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user