Check that the current directory is named correctly for package building
[stand.git] / debian / init.d.ex
blobab5bc4b9a4835504c0cbef45e8c3ff6e91dfc957
1 #! /bin/sh
3 # skeleton example file to build /etc/init.d/ scripts.
4 # This file should be used to construct scripts for /etc/init.d.
6 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
7 # Modified for Debian
8 # by Ian Murdock <imurdock@gnu.ai.mit.edu>.
9 # Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
11 # Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
14 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
15 DAEMON=/usr/sbin/stand
16 NAME=stand
17 DESC=stand
19 test -x $DAEMON || exit 0
21 LOGDIR=/var/log/stand
22 PIDFILE=/var/run/$NAME.pid
23 DODTIME=1 # Time to wait for the server to die, in seconds
24 # If this value is set too low you might not
25 # let some servers to die gracefully and
26 # 'restart' will not work
28 # Include stand defaults if available
29 if [ -f /etc/default/stand ] ; then
30 . /etc/default/stand
33 set -e
35 running_pid()
37 # Check if a given process pid's cmdline matches a given name
38 pid=$1
39 name=$2
40 [ -z "$pid" ] && return 1
41 [ ! -d /proc/$pid ] && return 1
42 cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
43 # Is this the expected child?
44 [ "$cmd" != "$name" ] && return 1
45 return 0
48 running()
50 # Check if the process is running looking at /proc
51 # (works for all users)
53 # No pidfile, probably no daemon present
54 [ ! -f "$PIDFILE" ] && return 1
55 # Obtain the pid and check it against the binary name
56 pid=`cat $PIDFILE`
57 running_pid $pid $NAME || return 1
58 return 0
61 force_stop() {
62 # Forcefully kill the process
63 [ ! -f "$PIDFILE" ] && return
64 if running ; then
65 kill -15 $pid
66 # Is it really dead?
67 [ -n "$DODTIME" ] && sleep "$DODTIME"s
68 if running ; then
69 kill -9 $pid
70 [ -n "$DODTIME" ] && sleep "$DODTIME"s
71 if running ; then
72 echo "Cannot kill $LABEL (pid=$pid)!"
73 exit 1
77 rm -f $PIDFILE
78 return 0
81 case "$1" in
82 start)
83 echo -n "Starting $DESC: "
84 start-stop-daemon --start --quiet --pidfile $PIDFILE \
85 --exec $DAEMON -- $DAEMON_OPTS
86 if running then
87 echo "$NAME."
88 else
89 echo " ERROR."
92 stop)
93 echo -n "Stopping $DESC: "
94 start-stop-daemon --stop --quiet --pidfile $PIDFILE \
95 --exec $DAEMON
96 echo "$NAME."
98 force-stop)
99 echo -n "Forcefully stopping $DESC: "
100 force_stop
101 if ! running then
102 echo "$NAME."
103 else
104 echo " ERROR."
107 #reload)
109 # If the daemon can reload its config files on the fly
110 # for example by sending it SIGHUP, do it here.
112 # If the daemon responds to changes in its config file
113 # directly anyway, make this a do-nothing entry.
115 # echo "Reloading $DESC configuration files."
116 # start-stop-daemon --stop --signal 1 --quiet --pidfile \
117 # /var/run/$NAME.pid --exec $DAEMON
119 force-reload)
121 # If the "reload" option is implemented, move the "force-reload"
122 # option to the "reload" entry above. If not, "force-reload" is
123 # just the same as "restart" except that it does nothing if the
124 # daemon isn't already running.
125 # check wether $DAEMON is running. If so, restart
126 start-stop-daemon --stop --test --quiet --pidfile \
127 /var/run/$NAME.pid --exec $DAEMON \
128 && $0 restart \
129 || exit 0
131 restart)
132 echo -n "Restarting $DESC: "
133 start-stop-daemon --stop --quiet --pidfile \
134 /var/run/$NAME.pid --exec $DAEMON
135 [ -n "$DODTIME" ] && sleep $DODTIME
136 start-stop-daemon --start --quiet --pidfile \
137 /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
138 echo "$NAME."
140 status)
141 echo -n "$LABEL is "
142 if running ; then
143 echo "running"
144 else
145 echo " not running."
146 exit 1
150 N=/etc/init.d/$NAME
151 # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
152 echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
153 exit 1
155 esac
157 exit 0