]> ToastFreeware Gitweb - philipp/winterrodeln/wrfeed.git/blob - wrfeed_webapp.sh
Set version number to 0.4.1.
[philipp/winterrodeln/wrfeed.git] / wrfeed_webapp.sh
1 #!/bin/sh
2
3 ME=$(basename $0)
4 DIR=$(dirname $0)
5 ARG=$1
6 APPDIR=$DIR
7 PORT=8766
8 USER=philipp
9 PIDFILE=/home/philipp/.wrfeed-webapp.pid
10 export WRFEED_SETTINGS=/home/philipp/daten/Winterrodeln/winterrodeln/wrfeed/wrfeed/development.cfg
11
12
13 die() {
14         echo "$1" >&2
15         usage
16         exit 1
17 }
18
19 usage() {
20         echo "Usage: ./$ME <start|stop|status|restart>." >&2
21 }
22
23 set -eu
24
25 [ -n "$ARG" ] || die "Missing argument."
26
27 start() {
28         /sbin/start-stop-daemon --chuid $USER --chdir "$APPDIR" --make-pidfile --background --pidfile $PIDFILE --exec /usr/bin/waitress-serve  --start -- --listen=[::1]:$PORT 'wrfeed:app'
29 }
30
31 status() {
32         set +e
33         /sbin/start-stop-daemon --status --pidfile "$PIDFILE"
34         case "$?" in
35                 0) 
36                         echo running
37                         ;;
38                 1)
39                         echo not running but PID file exists
40                         ;;
41                 3)
42                         echo not running
43                         ;;
44                 4)
45                         echo unable to determine status
46                         ;;
47                 *)
48                         die "unknown status"
49                         ;;
50         esac
51 }
52
53
54 stop() {
55         /sbin/start-stop-daemon --stop --remove-pidfile --pidfile "$PIDFILE"
56 }
57
58 case "$ARG" in
59         start)
60                 start
61                 ;;
62         stop)
63                 stop
64                 ;;
65         status)
66                 status
67                 ;;
68         restart)
69                 stop
70                 sleep 1
71                 start
72                 ;;
73         help|-h|--help)
74                 usage
75                 ;;
76         *)
77                 die "Unknown argument '$ARG'." >&2
78                 ;;
79 esac
80
81 exit $?