Now using start-stop-daemon and implement status.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 9 May 2019 19:04:34 +0000 (19:04 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 9 May 2019 19:04:34 +0000 (19:04 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrfeed/trunk@2807 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrfeed_webapp.sh

index ec8450718d375cebabffa57473a9ec9b3746c349..9275985352c8ff9b2f90c22e1ffe35db71ff5aae 100755 (executable)
@@ -5,6 +5,9 @@ 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() {
@@ -14,7 +17,7 @@ die() {
 }
 
 usage() {
-       echo "Usage: ./$ME <start|stop|restart>." >&2
+       echo "Usage: ./$ME <start|stop|status|restart>." >&2
 }
 
 set -eu
@@ -22,12 +25,34 @@ set -eu
 [ -n "$ARG" ] || die "Missing argument."
 
 start() {
-       cd "$APPDIR"
-       WRFEED_SETTINGS=development.cfg waitress-serve --listen=[::1]:$PORT '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
@@ -37,6 +62,9 @@ case "$ARG" in
        stop)
                stop
                ;;
+       status)
+               status
+               ;;
        restart)
                stop
                sleep 1