wok annotate busybox/stuff/daemon @ rev 25620
Up youtube-dl (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Aug 30 10:53:19 2023 +0000 (14 months ago) |
parents | ff5fd8788cd9 |
children |
rev | line source |
---|---|
pascal@5308 | 1 #!/bin/sh |
al@19161 | 2 # Start, stop and restart a busybox daemon 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) |
al@19159 | 11 DESC="$(_ '%s daemon' $NAME)" |
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 |
al@19159 | 16 *busybox) |
al@19159 | 17 DAEMON=$p/$NAME |
pascal@18590 | 18 break |
pascal@18590 | 19 esac |
pascal@18590 | 20 done |
pascal@5308 | 21 eval $(grep -i ^${NAME}_OPTIONS /etc/daemons.conf | sed 's/.*_OPT/OPT/') |
pascal@5308 | 22 PIDFILE=/var/run/$NAME.pid |
pascal@5308 | 23 |
pascal@5308 | 24 active_inetd() |
pascal@5308 | 25 { |
pascal@5308 | 26 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then |
pascal@5308 | 27 sed -i "s,^#\(.*$DAEMON.*\)$,\1," /etc/inetd.conf |
al@19159 | 28 /etc/init.d/inetd stop >/dev/null |
pascal@5308 | 29 exec /etc/init.d/inetd start |
pascal@5308 | 30 else |
al@19159 | 31 _ '%s is already active.' $NAME |
pascal@5308 | 32 exit 1 |
pascal@5308 | 33 fi |
pascal@5308 | 34 } |
pascal@5308 | 35 |
pascal@5308 | 36 inactive_inetd() |
pascal@5308 | 37 { |
pascal@5308 | 38 if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then |
al@19159 | 39 _ '%s is not active.' $NAME |
pascal@5308 | 40 exit 1 |
pascal@5308 | 41 else |
pascal@5308 | 42 sed -i "s,^.*$DAEMON.*$,#&," /etc/inetd.conf |
al@19159 | 43 /etc/init.d/inetd stop >/dev/null |
pascal@5308 | 44 exec /etc/init.d/inetd start |
pascal@5308 | 45 fi |
pascal@5308 | 46 } |
pascal@5308 | 47 |
pascal@5308 | 48 case "$1" in |
pascal@5308 | 49 start) |
pascal@5308 | 50 grep -qs $DAEMON /etc/inetd.conf && active_inetd |
pascal@5308 | 51 if active_pidfile $PIDFILE $NAME ; then |
al@19159 | 52 _ '%s is already running.' $NAME |
pascal@5308 | 53 exit 1 |
pascal@5308 | 54 fi |
al@19159 | 55 action 'Starting %s: %s...' "$DESC" $NAME |
al@19159 | 56 $DAEMON $OPTIONS |
pascal@22841 | 57 [ -f $PIDFILE ] || |
pascal@22841 | 58 ps x | sed "/$NAME/!d;/sed/d;/etc\\/init/d" | awk '{ print $1 }' > $PIDFILE |
pascal@5308 | 59 active_pidfile $PIDFILE $NAME |
pascal@5308 | 60 status |
pascal@5308 | 61 ;; |
pascal@5308 | 62 stop) |
pascal@5308 | 63 grep -qs $DAEMON /etc/inetd.conf && inactive_inetd |
pascal@5308 | 64 if ! active_pidfile $PIDFILE $NAME ; then |
al@19159 | 65 _ '%s is not running.' $NAME |
pascal@5308 | 66 exit 1 |
pascal@5308 | 67 fi |
al@19159 | 68 action 'Stopping %s: %s...' "$DESC" $NAME |
al@19159 | 69 kill $(cat $PIDFILE) |
pascal@5308 | 70 status |
pascal@5308 | 71 ;; |
pascal@5308 | 72 restart) |
pascal@5308 | 73 grep -qs $DAEMON /etc/inetd.conf && exit 0 |
pascal@5308 | 74 if ! active_pidfile $PIDFILE $NAME ; then |
al@19159 | 75 _ '%s is not running.' $NAME |
pascal@5308 | 76 exit 1 |
pascal@5308 | 77 fi |
al@19159 | 78 action 'Restarting %s: %s...' "$DESC" $NAME |
al@19159 | 79 kill $(cat $PIDFILE) |
pascal@5308 | 80 sleep 2 |
pascal@5308 | 81 $DAEMON $OPTIONS |
pascal@22841 | 82 [ -f $PIDFILE ] || |
pascal@22841 | 83 ps x | sed "/$NAME/!d;/sed/d;/etc\\/init/d" | awk '{ print $1 }' > $PIDFILE |
pascal@5308 | 84 active_pidfile $PIDFILE $NAME |
pascal@5308 | 85 status |
pascal@5308 | 86 ;; |
al@19159 | 87 *) |
al@19159 | 88 emsg "<n><b>$(_ 'Usage:')</b> /etc/init.d/$(basename $0) [start|stop|restart]" |
al@19159 | 89 newline |
pascal@5308 | 90 exit 1 |
pascal@5308 | 91 ;; |
pascal@5308 | 92 esac |
pascal@5308 | 93 |
pascal@5308 | 94 exit 0 |