-
Henrik Thostrup Jensen authored
set logfile in application creation and not at twistd (this is slighly more flexible and saves an init.d hack)
Henrik Thostrup Jensen authoredset logfile in application creation and not at twistd (this is slighly more flexible and saves an init.d hack)
opennsa 1.54 KiB
#! /bin/sh
# /etc/init.d/opennsa: Start the OpenNSA service
### BEGIN INIT INFO
# Provides: opennsa
# Required-Start: $network
# Required-Stop: $network
# Should-Start: $time
# Should-Stop: $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenNSA Service
### END INIT INFO
. /lib/lsb/init-functions
CONFIG_FILE=/etc/opennsa.conf
PIDFILE=/var/run/opennsa.pid
DEFAULT_USER=root
APP_START="from opennsa import setup ; application = setup.createApplication()"
do_start() {
# get runtime user from config file or set to root if not found
USER=`grep ^user= $CONFIG_FILE | tail -n 1 | cut -f2 -d'='`
USER=${USER:-$DEFAULT_USER}
USER_ID=`id -u $USER`
GROUP_ID=`id -g $USER`
# setup .tac file in temporary file (saves us a file in the distro and more importantly getting the location in this script).
TACFILE=`mktemp` || exit 1
echo $APP_START > $TACFILE
# start the opennsa service using twistd
twistd --pidfile $PIDFILE -y $TACFILE -u $USER_ID -g $GROUP_ID
}
do_stop() {
kill `cat $PIDFILE` || rm $PIDFILE
}
case "$1" in
start)
echo "Starting OpenNSA service"
do_start
;;
stop)
echo "Stopping OpenNSA service"
do_stop
;;
restart|reload)
echo "Restarting OpenNSA service"
do_stop
sleep 1 # erhmm...
do_start
;;
status)
status_of_proc -p $PIDFILE "twistd" "OpenNSA service" && exit 0 || exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit 0