16 # with your own name if you copy and modify this script. |
16 # with your own name if you copy and modify this script. |
17 |
17 |
18 # Do NOT "set -e" |
18 # Do NOT "set -e" |
19 |
19 |
20 # PATH should only include /usr/* if it runs after the mountnfs.sh script |
20 # PATH should only include /usr/* if it runs after the mountnfs.sh script |
21 PATH=/sbin:/usr/sbin:/bin:/usr/bin |
21 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin |
22 DESC="Description of the service" |
22 DESC="Tele-Watch" |
23 NAME=daemonexecutablename |
23 NAME=tele-watch |
24 DAEMON=/usr/sbin/$NAME |
24 DAEMON=/usr/local/sbin/$NAME |
25 DAEMON_ARGS="--options args" |
25 DAEMON_ARGS="/dtele:/.dtele" |
26 PIDFILE=/var/run/$NAME.pid |
26 PIDFILE=/var/run/$NAME.pid |
27 SCRIPTNAME=/etc/init.d/$NAME |
27 SCRIPTNAME=/etc/init.d/$NAME |
28 |
28 |
29 # Exit if the package is not installed |
29 # Exit if the package is not installed |
30 [ -x "$DAEMON" ] || exit 0 |
30 [ -x "$DAEMON" ] || exit 0 |
46 { |
46 { |
47 # Return |
47 # Return |
48 # 0 if daemon has been started |
48 # 0 if daemon has been started |
49 # 1 if daemon was already running |
49 # 1 if daemon was already running |
50 # 2 if daemon could not be started |
50 # 2 if daemon could not be started |
51 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ |
51 PID=$(pidof $NAME) && return 1 |
52 || return 1 |
52 |
53 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ |
53 if [ ! $PID ]; then |
54 $DAEMON_ARGS \ |
54 $DAEMON $DAEMON_ARGS || return 2 |
55 || return 2 |
55 fi |
56 # Add code here, if necessary, that waits for the process to be ready |
56 return 0 |
57 # to handle requests from services started subsequently which depend |
|
58 # on this one. As a last resort, sleep for some time. |
|
59 } |
57 } |
60 |
58 |
61 # |
59 # |
62 # Function that stops the daemon/service |
60 # Function that stops the daemon/service |
63 # |
61 # |
66 # Return |
64 # Return |
67 # 0 if daemon has been stopped |
65 # 0 if daemon has been stopped |
68 # 1 if daemon was already stopped |
66 # 1 if daemon was already stopped |
69 # 2 if daemon could not be stopped |
67 # 2 if daemon could not be stopped |
70 # other if a failure occurred |
68 # other if a failure occurred |
71 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME |
69 PID=$(pidof $NAME) || return 1 |
72 RETVAL="$?" |
|
73 [ "$RETVAL" = 2 ] && return 2 |
|
74 # Wait for children to finish too if this is a daemon that forks |
|
75 # and if the daemon is only ever run from this initscript. |
|
76 # If the above conditions are not satisfied then add some other code |
|
77 # that waits for the process to drop all resources that could be |
|
78 # needed by services started subsequently. A last resort is to |
|
79 # sleep for some time. |
|
80 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON |
|
81 [ "$?" = 2 ] && return 2 |
|
82 # Many daemons don't delete their pidfiles when they exit. |
|
83 rm -f $PIDFILE |
|
84 return "$RETVAL" |
|
85 } |
|
86 |
70 |
87 # |
71 $DAEMON --kill || return 2 |
88 # Function that sends a SIGHUP to the daemon/service |
|
89 # |
|
90 do_reload() { |
|
91 # |
|
92 # If the daemon can reload its configuration without |
|
93 # restarting (for example, when it is sent a SIGHUP), |
|
94 # then implement that here. |
|
95 # |
|
96 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME |
|
97 return 0 |
72 return 0 |
98 } |
73 } |
99 |
74 |
100 case "$1" in |
75 case "$1" in |
101 start) |
76 start) |
112 case "$?" in |
87 case "$?" in |
113 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
88 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
114 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
89 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
115 esac |
90 esac |
116 ;; |
91 ;; |
117 #reload|force-reload) |
|
118 # |
|
119 # If do_reload() is not implemented then leave this commented out |
|
120 # and leave 'force-reload' as an alias for 'restart'. |
|
121 # |
|
122 #log_daemon_msg "Reloading $DESC" "$NAME" |
|
123 #do_reload |
|
124 #log_end_msg $? |
|
125 #;; |
|
126 restart|force-reload) |
92 restart|force-reload) |
127 # |
93 # |
128 # If the "reload" option is implemented then remove the |
94 # If the "reload" option is implemented then remove the |
129 # 'force-reload' alias |
95 # 'force-reload' alias |
130 # |
96 # |