wok-next annotate busybox/stuff/daemon @ rev 18634

Add libzen, libmediainfo, mediainfo
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Nov 27 04:57:33 2015 +0200 (2015-11-27)
parents 1959b2e6b8a0
children 7f188676b59c
rev   line source
pascal@5308 1 #!/bin/sh
pascal@5308 2 # Start, stop and restart a busybox deamon on SliTaz, at boot time or
pascal@5308 3 # with the command line.
pascal@5308 4 #
pascal@5308 5 # To start daemon at boot time, just put the right name in the $RUN_DAEMONS
pascal@5308 6 # variable of /etc/rcS.conf and configure options with /etc/daemons.conf.
pascal@5308 7 #
pascal@5308 8 . /etc/init.d/rc.functions
pascal@5308 9
pascal@5308 10 NAME=$(basename $0)
pascal@5308 11 DESC="$NAME deamon"
pascal@5308 12 DAEMON=$(which $NAME)
pascal@18590 13 for p in ${PATH//:/ }; do
pascal@18590 14 [ -L $p/$NAME ] || continue
pascal@18590 15 case "$(readlink $p/$NAME)" in
pascal@18590 16 *busybox) DAEMON=$p/$NAME
pascal@18590 17 break
pascal@18590 18 esac
pascal@18590 19 done
pascal@5308 20 eval $(grep -i ^${NAME}_OPTIONS /etc/daemons.conf | sed 's/.*_OPT/OPT/')
pascal@5308 21 PIDFILE=/var/run/$NAME.pid
pascal@5308 22
pascal@5308 23 active_inetd()
pascal@5308 24 {
pascal@5308 25 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
pascal@5308 26 sed -i "s,^#\(.*$DAEMON.*\)$,\1," /etc/inetd.conf
pascal@5308 27 /etc/init.d/inetd stop > /dev/null
pascal@5308 28 exec /etc/init.d/inetd start
pascal@5308 29 else
pascal@5308 30 echo "$NAME is already active."
pascal@5308 31 exit 1
pascal@5308 32 fi
pascal@5308 33 }
pascal@5308 34
pascal@5308 35 inactive_inetd()
pascal@5308 36 {
pascal@5308 37 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then
pascal@5308 38 echo "$NAME is not active."
pascal@5308 39 exit 1
pascal@5308 40 else
pascal@5308 41 sed -i "s,^.*$DAEMON.*$,#&," /etc/inetd.conf
pascal@5308 42 /etc/init.d/inetd stop > /dev/null
pascal@5308 43 exec /etc/init.d/inetd start
pascal@5308 44 fi
pascal@5308 45 }
pascal@5308 46
pascal@5308 47 case "$1" in
pascal@5308 48 start)
pascal@5308 49 grep -qs $DAEMON /etc/inetd.conf && active_inetd
pascal@5308 50 if active_pidfile $PIDFILE $NAME ; then
pascal@5308 51 echo "$NAME is already running."
pascal@5308 52 exit 1
pascal@5308 53 fi
pascal@5308 54 echo -n "Starting $DESC: $NAME... "
pascal@5308 55 $DAEMON $OPTIONS
pascal@5308 56 [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
pascal@5308 57 active_pidfile $PIDFILE $NAME
pascal@5308 58 status
pascal@5308 59 ;;
pascal@5308 60 stop)
pascal@5308 61 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd
pascal@5308 62 if ! active_pidfile $PIDFILE $NAME ; then
pascal@5308 63 echo "$NAME is not running."
pascal@5308 64 exit 1
pascal@5308 65 fi
pascal@5308 66 echo -n "Stopping $DESC: $NAME... "
pascal@5308 67 kill `cat $PIDFILE`
pascal@5308 68 status
pascal@5308 69 ;;
pascal@5308 70 restart)
pascal@5308 71 grep -qs $DAEMON /etc/inetd.conf && exit 0
pascal@5308 72 if ! active_pidfile $PIDFILE $NAME ; then
pascal@5308 73 echo "$NAME is not running."
pascal@5308 74 exit 1
pascal@5308 75 fi
pascal@5308 76 echo -n "Restarting $DESC: $NAME... "
pascal@5308 77 kill `cat $PIDFILE`
pascal@5308 78 sleep 2
pascal@5308 79 $DAEMON $OPTIONS
pascal@5308 80 [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE
pascal@5308 81 active_pidfile $PIDFILE $NAME
pascal@5308 82 status
pascal@5308 83 ;;
pascal@5308 84 *)
pascal@5308 85 echo ""
pascal@5308 86 echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]"
pascal@5308 87 echo ""
pascal@5308 88 exit 1
pascal@5308 89 ;;
pascal@5308 90 esac
pascal@5308 91
pascal@5308 92 exit 0