wok-current view busybox/stuff/daemon @ rev 20065
busybox/udhcpc6: update script
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Sep 23 13:11:28 2017 +0200 (2017-09-23) |
parents | 7f188676b59c |
children | 314dd7281637 |
line source
1 #!/bin/sh
2 # Start, stop and restart a busybox daemon 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="$(_ '%s daemon' $NAME)"
12 DAEMON=$(which $NAME)
13 for p in ${PATH//:/ }; do
14 [ -L $p/$NAME ] || continue
15 case "$(readlink $p/$NAME)" in
16 *busybox)
17 DAEMON=$p/$NAME
18 break
19 esac
20 done
21 eval $(grep -i ^${NAME}_OPTIONS /etc/daemons.conf | sed 's/.*_OPT/OPT/')
22 PIDFILE=/var/run/$NAME.pid
24 active_inetd()
25 {
26 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
27 sed -i "s,^#\(.*$DAEMON.*\)$,\1," /etc/inetd.conf
28 /etc/init.d/inetd stop >/dev/null
29 exec /etc/init.d/inetd start
30 else
31 _ '%s is already active.' $NAME
32 exit 1
33 fi
34 }
36 inactive_inetd()
37 {
38 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
39 _ '%s is not active.' $NAME
40 exit 1
41 else
42 sed -i "s,^.*$DAEMON.*$,#&," /etc/inetd.conf
43 /etc/init.d/inetd stop >/dev/null
44 exec /etc/init.d/inetd start
45 fi
46 }
48 case "$1" in
49 start)
50 grep -qs $DAEMON /etc/inetd.conf && active_inetd
51 if active_pidfile $PIDFILE $NAME ; then
52 _ '%s is already running.' $NAME
53 exit 1
54 fi
55 action 'Starting %s: %s...' "$DESC" $NAME
56 $DAEMON $OPTIONS
57 [ -f $PIDFILE ] || pidof $NAME | awk '{print $1}' > $PIDFILE
58 active_pidfile $PIDFILE $NAME
59 status
60 ;;
61 stop)
62 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd
63 if ! active_pidfile $PIDFILE $NAME ; then
64 _ '%s is not running.' $NAME
65 exit 1
66 fi
67 action 'Stopping %s: %s...' "$DESC" $NAME
68 kill $(cat $PIDFILE)
69 status
70 ;;
71 restart)
72 grep -qs $DAEMON /etc/inetd.conf && exit 0
73 if ! active_pidfile $PIDFILE $NAME ; then
74 _ '%s is not running.' $NAME
75 exit 1
76 fi
77 action 'Restarting %s: %s...' "$DESC" $NAME
78 kill $(cat $PIDFILE)
79 sleep 2
80 $DAEMON $OPTIONS
81 [ -f $PIDFILE ] || pidof $NAME | awk '{print $1}' > $PIDFILE
82 active_pidfile $PIDFILE $NAME
83 status
84 ;;
85 *)
86 emsg "<n><b>$(_ 'Usage:')</b> /etc/init.d/$(basename $0) [start|stop|restart]"
87 newline
88 exit 1
89 ;;
90 esac
92 exit 0