buzz client
[googlelatitude] / debian / init.d.ex
1 #! /bin/sh
2 #
3 # skeleton      example file to build /etc/init.d/ scripts.
4 #               This file should be used to construct scripts for /etc/init.d.
5 #
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>
10 #
11 # Version:      @(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
12 #
13
14 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
15 DAEMON=/usr/sbin/googlelatitude
16 NAME=googlelatitude
17 DESC=googlelatitude
18
19 test -x $DAEMON || exit 0
20
21 LOGDIR=/var/log/googlelatitude
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
27
28 # Include googlelatitude defaults if available
29 if [ -f /etc/default/googlelatitude ] ; then
30         . /etc/default/googlelatitude
31 fi
32
33 set -e
34
35 running_pid()
36 {
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
46 }
47
48 running()
49 {
50 # Check if the process is running looking at /proc
51 # (works for all users)
52
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 $DAEMON || return 1
58     return 0
59 }
60
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
74             fi
75         fi
76     fi
77     rm -f $PIDFILE
78     return 0
79 }
80
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."
90         fi
91         ;;
92   stop)
93         echo -n "Stopping $DESC: "
94         start-stop-daemon --stop --quiet --pidfile $PIDFILE \
95                 --exec $DAEMON
96         echo "$NAME."
97         ;;
98   force-stop)
99         echo -n "Forcefully stopping $DESC: "
100         force_stop
101         if ! running ; then
102             echo "$NAME."
103         else
104             echo " ERROR."
105         fi
106         ;;
107   #reload)
108         #
109         #       If the daemon can reload its config files on the fly
110         #       for example by sending it SIGHUP, do it here.
111         #
112         #       If the daemon responds to changes in its config file
113         #       directly anyway, make this a do-nothing entry.
114         #
115         # echo "Reloading $DESC configuration files."
116         # start-stop-daemon --stop --signal 1 --quiet --pidfile \
117         #       /var/run/$NAME.pid --exec $DAEMON
118   #;;
119   force-reload)
120         #
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
130         ;;
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."
139         ;;
140   status)
141     echo -n "$LABEL is "
142     if running ;  then
143         echo "running"
144     else
145         echo " not running."
146         exit 1
147     fi
148     ;;
149   *)
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
154         ;;
155 esac
156
157 exit 0