]> ToastFreeware Gitweb - philipp/winterrodeln/wrfeed.git/blobdiff - wrfeed_webapp.sh
Now using start-stop-daemon and implement status.
[philipp/winterrodeln/wrfeed.git] / wrfeed_webapp.sh
index 42aca17e6127331960e5ad61d84514b38f863640..9275985352c8ff9b2f90c22e1ffe35db71ff5aae 100755 (executable)
@@ -1,5 +1,15 @@
 #!/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
@@ -7,24 +17,42 @@ die() {
 }
 
 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
@@ -34,6 +62,9 @@ case "$ARG" in
        stop)
                stop
                ;;
+       status)
+               status
+               ;;
        restart)
                stop
                sleep 1