Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@koha_ci_2:/home/koha/Koha# cat /etc/init.d/koha-plack-daemon
- #!/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/>.
- ### BEGIN INIT INFO
- # Provides: koha-plack-daemon
- # Required-Start: $remote_fs
- # Required-Stop: $remote_fs
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Plack server daemon for fast http-handling
- ### END INIT INFO
- set -e
- . /lib/lsb/init-functions
- HELPER_FUNCTIONS="/home/koha/Koha/debian/scripts/koha-functions.sh"
- RUNDIR="/var/run/koha"
- LOGDIR="/home/koha/koha-dev/var/log"
- PIDFILE="$RUNDIR/plack.pid"
- PLACKSOCKET="$RUNDIR/plack.sock"
- PSGIFILE="/home/koha/Koha/misc/plack/plack.psgi"
- MODE="deployment" #development|deployment|test
- LISTEN=":5000"
- #User and group must be the same as for apache2, eg. www-data. This is to prevent nasty surprises with priviledge escalation.
- #And so programs can communicate via the same unix-socket
- USER="www-data"
- GROUP="www-data"
- #Set Environment for koha-plack-daemon.sh
- export KOHA_CONF="/home/koha/koha-dev/etc/koha-conf.xml"
- export INTRANET_CGI_DIR="/home/koha/Koha"
- export OPAC_CGI_DIR="/home/koha/Koha/opac"
- export PERL_MODULE_DIR="/home/koha/Koha"
- export PLACK_DEBUG #This is set if debug-parameter is given or if mode is development
- #Make sure the pid-dir and log-dir exists
- mkdir -p $RUNDIR
- mkdir -p $LOGDIR
- # include helper functions
- if [ -f "$HELPER_FUNCTIONS" ]; then
- . "$HELPER_FUNCTIONS"
- else
- echo "Error: $HELPER_FUNCTIONS not present." 1>&2
- exit 1
- fi
- usage()
- {
- local scriptname=$(basename $0)
- cat <<EOF
- $scriptname
- This script lets you manage the plack daemon for your Koha instance.
- Usage:
- $scriptname start|stop|restart|reload [development|deployement|test] [debug] [debugger]
- $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
- reload Reload the application without losing connections
- debug Trigger PLACK_DEBUG -environment variable
- debugger Start perl with the -d -flag
- deployment Set the plack mode
- development Set the plack mode
- test Set the plack mode
- --help|-h Display this help message
- EXAMPLE
- bash -x /etc/init.d/koha-plack-daemon start development debug debugger
- EOF
- }
- start_plack()
- {
- _check_and_fix_perms
- DEBUGGER_STR=""
- test "$DEBUGGER" == "1" && DEBUGGER_STR="/usr/bin/perl -d "
- STARMANOPTS="-M FindBin \
- --user=$USER --group=$GROUP \
- --pid ${PIDFILE} \
- -E $MODE \
- ${PSGIFILE} "
- test "$MODE" != "deployment" && STARMANOPTS="$STARMANOPTS --workers 1"
- test "$MODE" == "deployment" && STARMANOPTS="$STARMANOPTS --daemonize \
- --max-requests 50 \
- --workers 2 \
- --access-log $LOGDIR/plack.log \
- --error-log $LOGDIR/plack-error.log \
- "
- test -n "$PLACKSOCKET" && STARMANOPTS="$STARMANOPTS --listen ${PLACKSOCKET} "
- test -n "$LISTEN" && STARMANOPTS="$STARMANOPTS --listen ${LISTEN} "
- if ! is_plack_running; then
- log_daemon_msg "Starting Plack daemon"
- if ${DEBUGGER_STR} ${STARMAN} ${STARMANOPTS}; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- else
- log_daemon_msg "Error: Plack already running"
- log_end_msg 1
- fi
- }
- stop_plack()
- {
- if is_plack_running; then
- log_daemon_msg "Stopping Plack daemon"
- if start-stop-daemon --pidfile ${PIDFILE} --stop; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- else
- log_daemon_msg "Error: Plack not running"
- log_end_msg 1
- fi
- }
- restart_plack()
- {
- if is_plack_running; then
- log_daemon_msg "Restarting Plack daemon"
- if stop_plack && start_plack; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- else
- log_daemon_msg "Error: Plack not running"
- log_end_msg 1
- fi
- }
- #Starman says he supports hot-reload. Maybe others do, but I only love starman.
- reload_starman()
- {
- if is_plack_running; then
- log_daemon_msg "Hot-reloading starman daemon !!!"
- if start-stop-daemon --pidfile ${PIDFILE} --stop --signal HUP; then
- log_end_msg 0
- else
- log_end_msg 1
- fi
- else
- log_daemon_msg "Error: starman not running"
- 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
- warn "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 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
- die "Error: only one action can be specified."
- fi
- }
- STARMAN=$(which starman)
- op=""
- quiet="no"
- # Read command line parameters
- while [ $# -gt 0 ]; do
- case "$1" in
- -h|--help)
- usage ; exit 0 ;;
- start)
- set_action "start"
- shift ;;
- stop)
- set_action "stop"
- shift ;;
- restart)
- set_action "restart"
- shift ;;
- reload)
- set_action "reload"
- shift ;;
- debug)
- export PLACK_DEBUG=1
- shift ;;
- debugger)
- DEBUGGER="1"
- shift ;;
- deployment)
- MODE="deployment"
- shift ;;
- development)
- MODE="development"
- export PLACK_DEBUG=1
- shift ;;
- test)
- MODE="test"
- shift ;;
- -*)
- die "Error: invalid option switch ($1)" ;;
- *)
- # We expect the remaining stuff are the instance names
- break ;;
- esac
- done
- if [ -z $PERL5LIB ]; then
- PERL5LIB="/home/koha/Koha"
- fi
- export PERL5LIB
- check_env_and_warn
- case $op in
- "start")
- start_plack
- ;;
- "stop")
- stop_plack
- ;;
- "restart")
- restart_plack
- ;;
- "reload")
- reload_starman
- ;;
- "enable")
- enable_plack
- ;;
- "disable")
- disable_plack
- ;;
- *)
- usage
- ;;
- esac
- exit 0
- root@koha_ci_2:/home/koha/Koha# cat /home/kivilahtio/prepare_remote_debugger.sh
- #!/bin/bash
- # Ansible managed: /home/ansible/KSAnsible/roles/koha/templates/home_prepare_remote_debugger.sh.j2 on hephaestus
- #
- # Loads the remote debugging environment variables to the running shell
- #
- # then you can just start perl scripts with the -d -flag and hopefully receive the remote debuggin session.
- # see http://docs.activestate.com/komodo/4.4/debugger.html
- #You must manually specify your remote connection settings
- REMOTEPORT=""
- test -z $REMOTEPORT && echo "\$REMOTEPORT not defined" && \
- echo "You must define where a debugger is listening for remote connections" && \
- echo "eg.: REMOTEPORT=192.168.1.101:8000" && \
- echo "" && \
- exit 1
- test $0 != "bash" && echo "Incorrect invocation: You must run me like:" && \
- echo ". prepare_remote_debugger.sh or source prepare_remote_debugger.sh" && \
- echo "" && \
- exit 1
- export PERL5LIB=/opt/Komodo-PerlRemoteDebugging-10.1.4/:$PERL5LIB
- export PERLDB_OPTS=RemotePort=$REMOTEPORT async=1
- export DBGP_IDEKEY=1221
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement