wok-6.x view busybox/stuff/daemon @ rev 23353
updated perl-io-socket-ssl (2.060 -> 2.068)
author | Hans-G?nter Theisgen |
---|---|
date | Tue Mar 31 09:53:02 2020 +0100 (2020-03-31) |
parents | ff5fd8788cd9 |
children |
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 ] ||
58 ps x | sed "/$NAME/!d;/sed/d;/etc\\/init/d" | awk '{ print $1 }' > $PIDFILE
59 active_pidfile $PIDFILE $NAME
60 status
61 ;;
62 stop)
63 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd
64 if ! active_pidfile $PIDFILE $NAME ; then
65 _ '%s is not running.' $NAME
66 exit 1
67 fi
68 action 'Stopping %s: %s...' "$DESC" $NAME
69 kill $(cat $PIDFILE)
70 status
71 ;;
72 restart)
73 grep -qs $DAEMON /etc/inetd.conf && exit 0
74 if ! active_pidfile $PIDFILE $NAME ; then
75 _ '%s is not running.' $NAME
76 exit 1
77 fi
78 action 'Restarting %s: %s...' "$DESC" $NAME
79 kill $(cat $PIDFILE)
80 sleep 2
81 $DAEMON $OPTIONS
82 [ -f $PIDFILE ] ||
83 ps x | sed "/$NAME/!d;/sed/d;/etc\\/init/d" | awk '{ print $1 }' > $PIDFILE
84 active_pidfile $PIDFILE $NAME
85 status
86 ;;
87 *)
88 emsg "<n><b>$(_ 'Usage:')</b> /etc/init.d/$(basename $0) [start|stop|restart]"
89 newline
90 exit 1
91 ;;
92 esac
94 exit 0