wok view busybox/stuff/daemon @ rev 18602
Up tazlito, tazpkg
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Nov 16 02:51:15 2015 +0200 (2015-11-16) |
parents | 1959b2e6b8a0 |
children | 7f188676b59c |
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 for p in ${PATH//:/ }; do
14 [ -L $p/$NAME ] || continue
15 case "$(readlink $p/$NAME)" in
16 *busybox) DAEMON=$p/$NAME
17 break
18 esac
19 done
20 eval $(grep -i ^${NAME}_OPTIONS /etc/daemons.conf | sed 's/.*_OPT/OPT/')
21 PIDFILE=/var/run/$NAME.pid
23 active_inetd()
24 {
25 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
26 sed -i "s,^#\(.*$DAEMON.*\)$,\1," /etc/inetd.conf
27 /etc/init.d/inetd stop > /dev/null
28 exec /etc/init.d/inetd start
29 else
30 echo "$NAME is already active."
31 exit 1
32 fi
33 }
35 inactive_inetd()
36 {
37 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
38 echo "$NAME is not active."
39 exit 1
40 else
41 sed -i "s,^.*$DAEMON.*$,#&," /etc/inetd.conf
42 /etc/init.d/inetd stop > /dev/null
43 exec /etc/init.d/inetd start
44 fi
45 }
47 case "$1" in
48 start)
49 grep -qs $DAEMON /etc/inetd.conf && active_inetd
50 if active_pidfile $PIDFILE $NAME ; then
51 echo "$NAME is already running."
52 exit 1
53 fi
54 echo -n "Starting $DESC: $NAME... "
55 $DAEMON $OPTIONS
56 [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
57 active_pidfile $PIDFILE $NAME
58 status
59 ;;
60 stop)
61 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd
62 if ! active_pidfile $PIDFILE $NAME ; then
63 echo "$NAME is not running."
64 exit 1
65 fi
66 echo -n "Stopping $DESC: $NAME... "
67 kill `cat $PIDFILE`
68 status
69 ;;
70 restart)
71 grep -qs $DAEMON /etc/inetd.conf && exit 0
72 if ! active_pidfile $PIDFILE $NAME ; then
73 echo "$NAME is not running."
74 exit 1
75 fi
76 echo -n "Restarting $DESC: $NAME... "
77 kill `cat $PIDFILE`
78 sleep 2
79 $DAEMON $OPTIONS
80 [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
81 active_pidfile $PIDFILE $NAME
82 status
83 ;;
84 *)
85 echo ""
86 echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]"
87 echo ""
88 exit 1
89 ;;
90 esac
92 exit 0