tizen 2.3.1 release
[external/busybox.git] / debian / busybox-syslogd.busybox-klogd.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-klogd klogd
25 # Required-Start:    $remote_fs
26 # Required-Stop:     $remote_fs
27 # Should-Start:      syslogd
28 # Should-Stop:
29 # Default-Start:     2 3 4 5
30 # Default-Stop:      0 1 6
31 # Short-Description: Starts klogd
32 # Description:       Starts the busybox klogd
33 ### END INIT INFO
34
35 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
36
37 NAME=klogd         # 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 KLOG_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 $KLOG_OPTS
75 }
76
77 stop_server() {
78         start-stop-daemon --stop --verbose --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
112   stop)
113         log_daemon_msg "Stopping $DESC" "$NAME"
114         if running ; then
115             # Only stop the server if we see it running
116                         errcode=0
117             stop_server || errcode=$?
118             log_end_msg $errcode
119         else
120             # If it's not running don't do anything
121             log_progress_msg "apparently not running"
122             log_end_msg 0
123             exit 0
124         fi
125         ;;
126
127   restart|force-reload)
128         log_daemon_msg "Restarting $DESC" "$NAME"
129                 errcode=0
130         stop_server || errcode=$?
131         # Wait some sensible amount, some server need this
132         [ -n "$DIETIME" ] && sleep $DIETIME
133         start_server || errcode=$?
134         [ -n "$STARTTIME" ] && sleep $STARTTIME
135         running || errcode=$?
136         log_end_msg $errcode
137         ;;
138
139   status)
140         log_daemon_msg "Checking status of $DESC" "$NAME"
141         if running ;  then
142             log_progress_msg "running"
143             log_end_msg 0
144         else
145             log_progress_msg "apparently not running"
146             log_end_msg 1
147             exit 1
148         fi
149         ;;
150
151   *)
152         N=/etc/init.d/$NAME
153         echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
154         exit 1
155         ;;
156 esac
157
158 exit 0