tizen 2.3.1 release
[external/busybox.git] / debian / busybox-syslogd.init
1 #!/bin/sh
2 #
3 # init.d script with LSB support.
4 #
5 # Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
6 # Copyright (c) 2008 Axel Beckert <abe@deuxchevaux.org>
7 #
8 # This is free software; you may redistribute it and/or modify
9 # it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2,
11 # or (at your option) any later version.
12 #
13 # This is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License with
19 # the Debian operating system, in /usr/share/common-licenses/GPL;  if
20 # not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
22 #
23 ### BEGIN INIT INFO
24 # Provides:          busybox-syslogd syslogd
25 # Required-Start:    $remote_fs
26 # Required-Stop:     $remote_fs
27 # Should-Start:      
28 # Should-Stop:
29 # Default-Start:     2 3 4 5
30 # Default-Stop:      0 1 6
31 # Short-Description: Starts syslogd
32 # Description:       Starts the busybox syslogd
33 ### END INIT INFO
34
35 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
36
37 NAME=syslogd         # Introduce the short server's name here
38 DAEMON=/sbin/$NAME # Introduce the server's location here
39 DESC="busybox' $NAME implementation" # Introduce a short description here
40 NEEDED_OPTS=''
41 DAEMON_USER='root'
42
43 test -x $DAEMON || exit 0
44
45 . /lib/lsb/init-functions
46
47 # Default options, these can be overriden by the information
48 # at /etc/default/$NAME
49 SYSLOG_OPTS=""          # Additional options given to the server
50
51 DIETIME=10              # Time to wait for the server to die, in seconds
52                         # If this value is set too low you might not
53                         # let some servers to die gracefully and
54                         # 'restart' will not work
55
56 #STARTTIME=2             # Time to wait for the server to start, in seconds
57                         # If this value is set each time the server is
58                         # started (on start or restart) the script will
59                         # stall to try to determine if it is running
60                         # If it is not set and the server takes time
61                         # to setup a pid file the log message might 
62                         # be a false positive (says it did not start
63                         # when it actually did)
64                         
65 # Include defaults if available
66 if [ -f /etc/default/busybox-syslogd ] ; then
67         . /etc/default/busybox-syslogd
68 fi
69
70 set -e
71
72 start_server() {
73         start-stop-daemon --start --verbose --name $NAME \
74                 --exec $DAEMON -- $NEEDED_OPTS $SYSLOG_OPTS
75 }
76
77 stop_server() {
78         start-stop-daemon --stop --quiet --name $NAME
79 }
80
81 running() {
82     cut -d ' ' -f 1-2 /proc/[0-9]*/stat 2> /dev/null | grep -F "($NAME)"
83 }
84
85 case "$1" in
86   start)
87         log_daemon_msg "Starting $DESC " "$NAME"
88         # Check if it's running first
89         if running ;  then
90             log_progress_msg "apparently already running"
91             log_end_msg 0
92             exit 0
93         fi
94         if start_server ; then
95             # NOTE: Some servers might die some time after they start,
96             # this code will detect this issue if STARTTIME is set
97             # to a reasonable value
98             [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time 
99             if  running ;  then
100                 # It's ok, the server started and is running
101                 log_end_msg 0
102             else
103                 # It is not running after we did start
104                 log_end_msg 1
105             fi
106         else
107             # Either we could not start it
108             log_end_msg 1
109         fi
110         ;;
111   stop)
112         log_daemon_msg "Stopping $DESC" "$NAME"
113         if running ; then
114             # Only stop the server if we see it running
115                         errcode=0
116             stop_server || errcode=$?
117             log_end_msg $errcode
118         else
119             # If it's not running don't do anything
120             log_progress_msg "apparently not running"
121             log_end_msg 0
122             exit 0
123         fi
124         ;;
125   restart|force-reload)
126         log_daemon_msg "Restarting $DESC" "$NAME"
127                 errcode=0
128         stop_server || errcode=$?
129         # Wait some sensible amount, some server need this
130         [ -n "$DIETIME" ] && sleep $DIETIME
131         start_server || errcode=$?
132         [ -n "$STARTTIME" ] && sleep $STARTTIME
133         running || errcode=$?
134         log_end_msg $errcode
135         ;;
136   status)
137
138         log_daemon_msg "Checking status of $DESC" "$NAME"
139         if running ;  then
140             log_progress_msg "running"
141             log_end_msg 0
142         else
143             log_progress_msg "apparently not running"
144             log_end_msg 1
145             exit 1
146         fi
147         ;;
148   # daemon cannot reload
149   reload)
150         log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
151         log_warning_msg "cannot re-read the config file (use restart)."
152         ;;
153
154   *)
155         N=/etc/init.d/$NAME
156         echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
157         exit 1
158         ;;
159 esac
160
161 exit 0