make init script actually run on startup and log output
[auerswald-callnotifier.git] / scripts / init.d / auerswald-callnotifier
1 #! /bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:          auerswald-callnotifier
5 # Required-Start:    $local_fs $network $syslog mysql slapd
6 # Required-Stop:     $local_fs $network $syslog
7 # Default-Start:     2 3 4 5
8 # Default-Stop:      0 1 6
9 # Short-Description: Call notification program
10 ### END INIT INFO
11
12 # Author: Christian Weiske <cweiske@cweiske.de>
13
14 # PATH should only include /usr/* if it runs after the mountnfs.sh script
15 PATH=/sbin:/usr/sbin:/bin:/usr/bin
16 DESC="Run auerswald callnotifier"
17 NAME=auerswald-callnotifier
18 DAEMON=/usr/bin/php
19 DAEMON_ARGS="/usr/local/src/auerswald-callnotifier/callnotifier.php"
20 PIDFILE=/var/run/$NAME.pid
21 SCRIPTNAME=/etc/init.d/$NAME
22
23 # Exit if the package is not installed
24 [ -x "$DAEMON" ] || exit 0
25
26 # Load the VERBOSE setting and other rcS variables
27 . /lib/init/vars.sh
28
29 # Define LSB log_* functions.
30 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
31 # and status_of_proc is working.
32 . /lib/lsb/init-functions
33
34 do_start()
35 {
36         # Return
37         #   0 if daemon has been started
38         #   1 if daemon was already running
39         #   2 if daemon could not be started
40         start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
41             || return 1
42         start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE\
43             --startas /bin/bash -- -c "exec $DAEMON $DAEMON_ARGS >> /var/log/$NAME.log 2>&1" \
44             || return 2
45         #--exec $DAEMON -- $DAEMON_ARGS \
46 }
47
48 do_stop()
49 {
50         # Return
51         #   0 if daemon has been stopped
52         #   1 if daemon was already stopped
53         #   2 if daemon could not be stopped
54         #   other if a failure occurred
55         start-stop-daemon --stop --retry=TERM/5/KILL/5 --pidfile $PIDFILE
56         RETVAL="$?"
57         [ "$RETVAL" = 2 ] && return 2
58         [ "$RETVAL" = 0 ] && rm -f $PIDFILE
59         return "$RETVAL"
60 }
61
62 case "$1" in
63   start)
64         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
65         do_start
66         case "$?" in
67                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
68                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
69         esac
70         ;;
71   stop)
72         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
73         do_stop
74         case "$?" in
75                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
76                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
77         esac
78         ;;
79   status)
80        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
81        ;;
82   restart|force-reload)
83         log_daemon_msg "Restarting $DESC" "$NAME"
84         do_stop
85         case "$?" in
86           0|1)
87                 do_start
88                 case "$?" in
89                         0) log_end_msg 0 ;;
90                         1) log_end_msg 1 ;; # Old process is still running
91                         *) log_end_msg 1 ;; # Failed to start
92                 esac
93                 ;;
94           *)
95                 # Failed to stop
96                 log_end_msg 1
97                 ;;
98         esac
99         ;;
100   *)
101         #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
102         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
103         exit 3
104         ;;
105 esac
106
107 :