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