#!/bin/sh
+ME=$(basename $0)
+DIR=$(dirname $0)
+ARG=$1
+APPDIR=$DIR
+PORT=8766
+USER=philipp
+PIDFILE=/home/philipp/.wrfeed-webapp.pid
+export WRFEED_SETTINGS=/home/philipp/daten/Winterrodeln/winterrodeln/wrfeed/wrfeed/development.cfg
+
+
die() {
echo "$1" >&2
usage
}
usage() {
- echo "Usage: ./$ME <start|stop|restart>." >&2
+ echo "Usage: ./$ME <start|stop|status|restart>." >&2
}
-ME=$(basename $0)
-DIR=$(dirname $0)
-ARG=$1
-
set -eu
[ -n "$ARG" ] || die "Missing argument."
start() {
- cd "$DIR"
- WRFEED_SETTINGS=development.cfg waitress-serve --listen=[::1]:8766 'wrfeed:app' &
+ /sbin/start-stop-daemon --chuid $USER --chdir "$APPDIR" --make-pidfile --background --pidfile $PIDFILE --exec /usr/bin/waitress-serve --start -- --listen=[::1]:$PORT 'wrfeed:app'
+}
+
+status() {
+ set +e
+ /sbin/start-stop-daemon --status --pidfile "$PIDFILE"
+ case "$?" in
+ 0)
+ echo running
+ ;;
+ 1)
+ echo not running but PID file exists
+ ;;
+ 3)
+ echo not running
+ ;;
+ 4)
+ echo unable to determine status
+ ;;
+ *)
+ die "unknown status"
+ ;;
+ esac
}
+
stop() {
- killall waitress-serve
+ /sbin/start-stop-daemon --stop --remove-pidfile --pidfile "$PIDFILE"
}
case "$ARG" in
stop)
stop
;;
+ status)
+ status
+ ;;
restart)
stop
sleep 1