2006-05-15 11:41:00 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# runlevel script of the cryptobox package
|
|
|
|
#
|
|
|
|
# Copyright (c) 02006, senselab
|
|
|
|
#
|
|
|
|
# see LICENSE file in this package for details
|
|
|
|
#
|
|
|
|
|
2006-11-22 16:21:21 +01:00
|
|
|
### BEGIN INIT INFO
|
2006-11-27 20:25:26 +01:00
|
|
|
# Provides: cryptobox-server
|
2006-11-22 16:21:21 +01:00
|
|
|
# Required-Start: $network $local_fs $remote_fs
|
|
|
|
# Required-Stop: $network $local_fs $remote_fs
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: start CryptoBox webserver
|
|
|
|
### END INIT INFO
|
|
|
|
|
2006-12-19 23:33:02 +01:00
|
|
|
# include some useful functions to unify our output format
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
|
2006-05-15 11:41:00 +02:00
|
|
|
# read the default setting file, if it exists
|
2006-12-19 23:16:44 +01:00
|
|
|
[ -r /etc/default/cryptobox-server ] && . /etc/default/cryptobox-server
|
2006-05-15 11:41:00 +02:00
|
|
|
|
2006-11-27 20:25:26 +01:00
|
|
|
# set default values (if not defined in /etc/default/cryptobox-server)
|
2006-05-15 11:41:00 +02:00
|
|
|
NO_START=${NO_START:-0}
|
2006-11-10 10:05:14 +01:00
|
|
|
RUNAS=${RUNAS:-cryptobox}
|
2006-11-23 20:13:08 +01:00
|
|
|
PORT=${PORT:-8080}
|
|
|
|
HOST=${HOST:-}
|
2006-11-27 20:25:26 +01:00
|
|
|
LOGFILE=/var/log/cryptobox-server/webserver.log
|
2006-11-23 20:13:08 +01:00
|
|
|
SERVER_OPTS=${SERVER_OPTS:-}
|
2006-11-27 20:25:26 +01:00
|
|
|
CONF_FILE=/etc/cryptobox-server/cryptobox.conf
|
2006-11-10 10:05:14 +01:00
|
|
|
|
2006-11-23 21:52:30 +01:00
|
|
|
DAEMON=/usr/sbin/CryptoBoxWebserver
|
2006-12-18 14:37:08 +01:00
|
|
|
# default install location is /usr/bin/ - debian installation requires /usr/sbin/
|
|
|
|
test -x "$DAEMON" || DAEMON=/usr/bin/CryptoBoxWebserver
|
2006-12-05 13:24:47 +01:00
|
|
|
PYTHON_EXEC=/usr/bin/python
|
2006-11-27 20:25:26 +01:00
|
|
|
PIDFILE=/var/run/cryptobox-server/webserver.pid
|
2006-11-10 10:05:14 +01:00
|
|
|
DESC="CryptoBox Daemon (webinterface)"
|
2006-12-19 15:02:30 +01:00
|
|
|
OPTIONS="-B --pidfile=$PIDFILE --config=$CONF_FILE --logfile=$LOGFILE --host=$HOST --port=$PORT --user=$RUNAS $SERVER_OPTS"
|
2006-11-10 10:05:14 +01:00
|
|
|
|
2006-12-19 23:33:02 +01:00
|
|
|
# quit if NO_START is 1 (see /etc/default/cryptobox-server)
|
|
|
|
[ "$NO_START" = "1" ] && log_daemon_msg "Not starting $DESC please edit /etc/default/cryptobox-server!" && exit 0
|
|
|
|
|
2006-11-22 16:21:21 +01:00
|
|
|
# check if the package is installed
|
2006-11-23 20:13:08 +01:00
|
|
|
test -e "$DAEMON" || exit 0
|
2006-11-10 10:05:14 +01:00
|
|
|
|
2006-11-22 16:21:21 +01:00
|
|
|
|
2006-05-15 11:41:00 +02:00
|
|
|
case "$1" in
|
|
|
|
start )
|
2006-12-05 13:24:47 +01:00
|
|
|
# create the directory of the pid file if necessary
|
2006-11-23 20:13:08 +01:00
|
|
|
PIDDIR=$(dirname "$PIDFILE")
|
2007-01-06 12:40:38 +01:00
|
|
|
if [ ! -d "$PIDDIR" ]
|
2006-11-23 20:13:08 +01:00
|
|
|
then mkdir -p "$PIDDIR"
|
2006-12-19 15:02:30 +01:00
|
|
|
# necessary: the cryptobox server needs the permission to remove the pid file
|
2006-11-23 20:13:08 +01:00
|
|
|
chown $RUNAS:root "$PIDDIR"
|
|
|
|
chmod 755 "$PIDDIR"
|
|
|
|
fi
|
2007-01-06 12:40:38 +01:00
|
|
|
# create the directory of the pid file if necessary
|
|
|
|
LOGDIR=$(dirname "$LOGFILE")
|
|
|
|
if [ ! -d "$LOGDIR" ]
|
|
|
|
then mkdir -p "$LOGDIR"
|
|
|
|
chown $RUNAS:root "$LOGDIR"
|
|
|
|
chmod 750 "$LOGDIR"
|
|
|
|
fi
|
2006-11-23 20:13:08 +01:00
|
|
|
log_daemon_msg "Starting $DESC"
|
2006-11-22 16:21:21 +01:00
|
|
|
if start-stop-daemon \
|
2006-12-19 15:02:30 +01:00
|
|
|
--quiet --start --user $RUNAS --pidfile "$PIDFILE" \
|
2006-12-05 13:24:47 +01:00
|
|
|
--startas "$PYTHON_EXEC" -- "$DAEMON" $OPTIONS
|
2006-11-22 16:21:21 +01:00
|
|
|
then log_end_msg 0
|
|
|
|
else log_end_msg 1
|
|
|
|
fi
|
2006-05-15 11:41:00 +02:00
|
|
|
;;
|
|
|
|
stop )
|
2006-12-19 23:33:02 +01:00
|
|
|
log_daemon_msg "Stopping $DESC"
|
2006-12-05 13:24:47 +01:00
|
|
|
# if there is no pid file for some reason, then we try to find the process
|
|
|
|
if test ! -e "$PIDFILE"
|
|
|
|
then if start-stop-daemon --quiet --stop --user "$RUNAS" --exec "$PYTHON_EXEC"
|
|
|
|
then log_end_msg 0
|
|
|
|
else log_end_msg 1
|
|
|
|
fi
|
|
|
|
# there is a pid file - great!
|
|
|
|
elif start-stop-daemon --quiet --stop \
|
2006-11-23 20:13:08 +01:00
|
|
|
--pidfile "$PIDFILE" \
|
|
|
|
--user "$RUNAS"
|
2006-11-24 12:03:20 +01:00
|
|
|
then test -e "$PIDFILE" && rm "$PIDFILE"
|
2006-11-22 16:21:21 +01:00
|
|
|
log_end_msg 0
|
|
|
|
else log_end_msg 1
|
|
|
|
fi
|
2006-05-15 11:41:00 +02:00
|
|
|
;;
|
2006-11-22 16:21:21 +01:00
|
|
|
reload | force-reload | restart )
|
2006-05-15 11:41:00 +02:00
|
|
|
"$0" stop
|
2006-12-19 15:02:30 +01:00
|
|
|
sleep 3
|
2006-05-15 11:41:00 +02:00
|
|
|
"$0" start
|
2006-05-29 11:34:54 +02:00
|
|
|
;;
|
2006-11-23 20:13:08 +01:00
|
|
|
status )
|
|
|
|
echo -n "$DESC "
|
|
|
|
if start-stop-daemon --stop --signal 0 --quiet \
|
2006-11-24 12:03:20 +01:00
|
|
|
--pidfile "$PIDFILE" --user "$RUNAS"
|
2006-11-23 20:13:08 +01:00
|
|
|
then echo "running"
|
|
|
|
exit 0
|
|
|
|
else if [ -e "$PIDFILE" ]
|
|
|
|
then echo "failed"
|
|
|
|
exit 1
|
|
|
|
else echo "not running"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2006-05-15 11:41:00 +02:00
|
|
|
* )
|
2006-11-23 20:13:08 +01:00
|
|
|
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
|
2006-05-15 11:41:00 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-11-22 16:21:21 +01:00
|
|
|
exit 0
|
|
|
|
|