wok view busybox/stuff/daemon @ rev 16805
Up hastapd (2.2)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jul 06 10:56:03 2014 +0200 (2014-07-06) |
parents | |
children | d2c1950b6f95 |
line source
1 #!/bin/sh
2 # Start, stop and restart a busybox deamon on SliTaz, at boot time or
3 # with the command line.
4 #
5 # To start daemon at boot time, just put the right name in the $RUN_DAEMONS
6 # variable of /etc/rcS.conf and configure options with /etc/daemons.conf.
7 #
8 . /etc/init.d/rc.functions
10 NAME=$(basename $0)
11 DESC="$NAME deamon"
12 DAEMON=$(which $NAME)
13 eval $(grep -i ^${NAME}_OPTIONS /etc/daemons.conf | sed 's/.*_OPT/OPT/')
14 PIDFILE=/var/run/$NAME.pid
16 active_inetd()
17 {
18 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
19 sed -i "s,^#\(.*$DAEMON.*\)$,\1," /etc/inetd.conf
20 /etc/init.d/inetd stop > /dev/null
21 exec /etc/init.d/inetd start
22 else
23 echo "$NAME is already active."
24 exit 1
25 fi
26 }
28 inactive_inetd()
29 {
30 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
31 echo "$NAME is not active."
32 exit 1
33 else
34 sed -i "s,^.*$DAEMON.*$,#&," /etc/inetd.conf
35 /etc/init.d/inetd stop > /dev/null
36 exec /etc/init.d/inetd start
37 fi
38 }
40 case "$1" in
41 start)
42 grep -qs $DAEMON /etc/inetd.conf && active_inetd
43 if active_pidfile $PIDFILE $NAME ; then
44 echo "$NAME is already running."
45 exit 1
46 fi
47 echo -n "Starting $DESC: $NAME... "
48 $DAEMON $OPTIONS
49 [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
50 active_pidfile $PIDFILE $NAME
51 status
52 ;;
53 stop)
54 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd
55 if ! active_pidfile $PIDFILE $NAME ; then
56 echo "$NAME is not running."
57 exit 1
58 fi
59 echo -n "Stopping $DESC: $NAME... "
60 kill `cat $PIDFILE`
61 status
62 ;;
63 restart)
64 grep -qs $DAEMON /etc/inetd.conf && exit 0
65 if ! active_pidfile $PIDFILE $NAME ; then
66 echo "$NAME is not running."
67 exit 1
68 fi
69 echo -n "Restarting $DESC: $NAME... "
70 kill `cat $PIDFILE`
71 sleep 2
72 $DAEMON $OPTIONS
73 [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
74 active_pidfile $PIDFILE $NAME
75 status
76 ;;
77 *)
78 echo ""
79 echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]"
80 echo ""
81 exit 1
82 ;;
83 esac
85 exit 0