wok-tiny view busybox-net/stuff/daemon @ rev 173

Fix ctorrent-dnh & tfttest
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 14 09:04:04 2021 +0000 (2021-07-14)
parents a28c45a86936
children
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=$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 [ $DAEMON != inetd ] &&
43 grep -qs $DAEMON /etc/inetd.conf && active_inetd
44 if active_pidfile $PIDFILE $NAME ; then
45 echo "$NAME is already running."
46 exit 1
47 fi
48 echo -n "Starting $DESC: $NAME... "
49 $DAEMON $OPTIONS
50 [ -f $PIDFILE ] || ps | sed "/$NAME/!d;/etc\/init/d;s| .*||" > $PIDFILE
51 active_pidfile $PIDFILE $NAME
52 status
53 ;;
54 stop)
55 [ $DAEMON != inetd ] &&
56 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd
57 if ! active_pidfile $PIDFILE $NAME ; then
58 echo "$NAME is not running."
59 exit 1
60 fi
61 echo -n "Stopping $DESC: $NAME... "
62 kill `cat $PIDFILE`
63 status
64 ;;
65 restart)
66 [ $DAEMON != inetd ] &&
67 grep -qs $DAEMON /etc/inetd.conf && exit 0
68 if ! active_pidfile $PIDFILE $NAME ; then
69 echo "$NAME is not running."
70 exit 1
71 fi
72 echo -n "Restarting $DESC: $NAME... "
73 kill `cat $PIDFILE`
74 sleep 2
75 $DAEMON $OPTIONS
76 [ -f $PIDFILE ] || ps | sed "/$NAME/!d;/etc\/init/d;s| .*||" > $PIDFILE
77 active_pidfile $PIDFILE $NAME
78 status
79 ;;
80 *)
81 echo ""
82 echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]"
83 echo ""
84 exit 1
85 ;;
86 esac
88 exit 0