completed setup for installation, fixed robustness problem.
[upnpmonitor] / wamblee-upnpmonitor / files / etc / init.d / upnpmonitor
1 #!/bin/bash
2 #
3 # Author: Erik Brakkee
4 #
5 # init.d/upnpmonitor
6 #
7 # System startup script for the upnp monitor.
8 #
9 ### BEGIN INIT INFO
10 # Provides: upnpmonitor
11 # Required-Start: $remote_fs $syslog 
12 # Required-Stop:  $remote_fs $syslog
13 # Default-Start:  3 5
14 # Default-Stop:   0 1 2 6
15 # Description:    Start upnpmonitor 
16 ### END INIT INFO
17
18 test -s /etc/rc.status && . /etc/rc.status && rc_reset
19
20 # Determine the base and follow a runlevel link name.
21 base=${0##*/}
22 link=${base#*[SK][0-9][0-9]}
23
24 # Force execution if not called by a runlevel directory.
25 #test $link = $base && START_GLASSFISH=yes
26 #test "$START_UPNPMONITOR" = yes || exit 0
27
28 # setup environment
29 [[ -r /etc/profile.local ]] && . /etc/profile.local
30  
31
32 exec=/opt/upnpmonitor/bin/upnpmonitor
33 prog=${exec##*/}
34 lockfile=/var/lock/upnpmonitor
35
36 echo "prog = $prog"
37
38 start()
39 {
40     echo -n "Starting upnp monitor: "
41     if [[ ! -r "$lockfile" ]]
42     then
43       su upnpmonitor -c "$exec" > /var/log/upnpmonitor.log 2>&1 & 
44       pid=$!
45       rv=$?
46       [ $rv -eq 0 ] && echo $pid > $lockfile
47     else
48       rv=0
49     fi
50     return $rv
51 }
52
53 stop()
54 {
55     echo -n "Shutting down upnpmonitor: "
56     kill -2 $( < $lockfile )
57     rv=$?
58     rm -f $lockfile
59     return $rv
60 }
61
62 restart()
63 {
64     stop
65     start
66 }
67
68 case "$1" in
69     start|stop|restart)
70         if ! $1
71         then
72           return=$rc_failed
73         fi
74         rc_status -v
75         ;;
76     force-reload)
77         restart
78         ;;
79     status)
80         echo -n "Checking for upnp monitor status..."
81         checkproc $prog
82         rc_status -v 
83         ;;
84     try-restart|condrestart)
85         if status $prog >/dev/null ; then
86             restart
87         fi
88         ;;
89     reload)
90         echo "Service ${0##*/} does not support the reload action " 1>&2
91         exit 3
92         ;;
93     *)
94         echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" 1>&2
95         exit 2
96         ;;
97 esac
98
99