/[projects]/smsdaemon/scripts/smsdaemon-initscript
ViewVC logotype

Contents of /smsdaemon/scripts/smsdaemon-initscript

Parent Directory Parent Directory | Revision Log Revision Log


Revision 170 - (show annotations) (download)
Tue Dec 9 22:16:26 2008 UTC (15 years, 5 months ago) by torben
File size: 3377 byte(s)
Added something more like a real initscript

1 #! /bin/sh
2 #
3 # smsdaemon Startup script for the SMS daemon
4 #
5
6 ### BEGIN INIT INFO
7 # Provides: smsdaemon
8 # Required-Start: $syslog
9 # Required-Stop: $syslog
10 # Should-Start: $local_fs
11 # Should-Stop: $local_fs
12 # Default-Start: 2 3 4 5
13 # Default-Stop: 0 1 6
14 # Short-Description: starts smsdaemon
15 ### END INIT INFO
16
17 PATH=/sbin:/bin:/usr/sbin:/usr/bin
18 DAEMON=/usr/local/sbin/smsdaemon
19 NAME=smsdaemon
20 PACKAGE=smsdaemon
21 DESC='SMS Daemon'
22
23 PIDFILE="/var/run/smsdaemon.pid"
24
25
26
27 test -x $DAEMON || exit 0
28
29
30
31
32 start () {
33
34 if ! ps -C smsdaemon > /dev/null 2>&1 ; then
35
36 if [ -f $PIDFILE ]; then
37 rm $PIDFILE
38 fi
39 fi
40
41 #make sure we have the directories and access where needed
42 if [ ! -d $(dirname $PIDFILE) ]; then
43 install -d -o $USER -g $GROUP -m 755 $(dirname $PIDFILE)
44 else
45 chown -R $USER:$GROUP $(dirname $PIDFILE)
46 fi
47
48
49
50 # Start the daemon
51 ARGS="--daemon"
52 if start-stop-daemon -q --start --background -p $PIDFILE --exec $DAEMON -- $ARGS ; then
53 echo "$NAME."
54 else
55 echo "$NAME already running."
56 fi
57
58 sleep 1
59 }
60
61 forcestop ()
62 {
63 if [ -f $PIDFILE ]; then
64 PID=`cat $PIDFILE 2>/dev/null`
65 fi
66
67 if ! kill -0 $PID 2>/dev/null 2>/dev/null; then
68 echo "$NAME not running."
69 else
70 kill -9 $PID
71 if [ -f $PIDFILE ]; then
72 rm $PIDFILE
73 fi
74
75 if kill -0 $PID 2>/dev/null 2>/dev/null; then
76 echo "Failed."
77 else
78 echo "$NAME."
79 fi
80 fi
81 }
82
83 status()
84 {
85 if [ ! -f $PIDFILE ]; then
86 return 1;
87 fi
88
89 start-stop-daemon --start --quiet -p $PIDFILE --exec $DAEMON --test > /dev/null
90 if [ "$?" = '0' ]; then
91 return 1 # Daemon is not running
92 else
93 return 0 # Daemon is running
94 fi
95 }
96
97 stop () {
98
99 restartmode="0"
100
101 if [ "$1" = 'restart' ]; then
102 restartmode=1
103 fi
104
105 if [ -f $PIDFILE ]; then
106 PID=`cat $PIDFILE 2>/dev/null`
107 fi
108
109 if ! kill -0 $PID 2>/dev/null 2>/dev/null; then
110 echo "$NAME not running."
111
112 if [ "$restartmode" -lt 1 ]
113 then
114 return 0
115 fi
116 fi
117
118 infofound=0
119 maxwait=15
120
121 start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
122
123 #
124 # Now we have to wait until smsd has _really_ stopped
125 #
126 sleep 1
127
128 if test -n "$PID" && kill -0 $PID 2>/dev/null
129 then
130 echo -n "(waiting..."
131
132 seconds=0
133 while kill -0 $PID 2>/dev/null
134 do
135 if [ $infofound -lt 1 ]; then
136 if [ -f $INFOFILE ]; then
137 infofound=1
138 fi
139 fi
140
141 if [ $infofound -lt 1 ]; then
142 seconds=`expr $seconds + 1`
143 fi
144
145 if [ $seconds -ge $maxwait ]; then
146 echo -n "failed)"
147 echo -n "Timeout occured, killing smsd hardly."
148
149 kill -9 $PID
150 if [ -f $PIDFILE ]; then
151 rm $PIDFILE
152 fi
153
154 echo ""
155 exit 0
156 fi
157
158 sleep 1
159 done
160
161 echo -n "done)"
162 fi
163
164 if [ "$restartmode" -lt 1 ]; then
165 echo "$NAME."
166 fi
167 }
168
169 case "$1" in
170 start)
171 echo -n "Starting $DESC: "
172 start
173 ;;
174
175 stop)
176 echo -n "Stopping $DESC: "
177 stop
178 ;;
179
180 status)
181 echo -n "Status of $DESC: "
182 status
183 case "$?" in
184 0)
185 echo "$NAME is running."
186 ;;
187 1)
188 echo "$NAME is not running."
189 ;;
190 esac
191 ;;
192 force-stop)
193 echo -n "Forcing stop of $DESC: "
194 force-stop
195 echo "$NAME."
196
197 ;;
198
199 restart|reload|force-reload)
200 echo -n "Restarting $DESC: "
201 stop restart
202 start
203 ;;
204
205 *)
206 echo "Usage: /etc/init.d/$NAME {start|stop|force-stop|reload|force-reload|restart|status}"
207 exit 3
208 ;;
209 esac
210
211 exit 0

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20