wok-6.x diff busybox/stuff/daemon @ rev 12157
Up: slitaz-base-files (4.4.1) - Now include httphelper, calc
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Mar 17 14:21:12 2012 +0100 (2012-03-17) |
parents | |
children | d2c1950b6f95 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/busybox/stuff/daemon Sat Mar 17 14:21:12 2012 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +#!/bin/sh 1.5 +# Start, stop and restart a busybox deamon on SliTaz, at boot time or 1.6 +# with the command line. 1.7 +# 1.8 +# To start daemon at boot time, just put the right name in the $RUN_DAEMONS 1.9 +# variable of /etc/rcS.conf and configure options with /etc/daemons.conf. 1.10 +# 1.11 +. /etc/init.d/rc.functions 1.12 + 1.13 +NAME=$(basename $0) 1.14 +DESC="$NAME deamon" 1.15 +DAEMON=$(which $NAME) 1.16 +eval $(grep -i ^${NAME}_OPTIONS /etc/daemons.conf | sed 's/.*_OPT/OPT/') 1.17 +PIDFILE=/var/run/$NAME.pid 1.18 + 1.19 +active_inetd() 1.20 +{ 1.21 +if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then 1.22 + sed -i "s,^#\(.*$DAEMON.*\)$,\1," /etc/inetd.conf 1.23 + /etc/init.d/inetd stop > /dev/null 1.24 + exec /etc/init.d/inetd start 1.25 +else 1.26 + echo "$NAME is already active." 1.27 + exit 1 1.28 +fi 1.29 +} 1.30 + 1.31 +inactive_inetd() 1.32 +{ 1.33 +if grep $DAEMON /etc/inetd.conf | grep -q ^\#; then 1.34 + echo "$NAME is not active." 1.35 + exit 1 1.36 +else 1.37 + sed -i "s,^.*$DAEMON.*$,#&," /etc/inetd.conf 1.38 + /etc/init.d/inetd stop > /dev/null 1.39 + exec /etc/init.d/inetd start 1.40 +fi 1.41 +} 1.42 + 1.43 +case "$1" in 1.44 + start) 1.45 + grep -qs $DAEMON /etc/inetd.conf && active_inetd 1.46 + if active_pidfile $PIDFILE $NAME ; then 1.47 + echo "$NAME is already running." 1.48 + exit 1 1.49 + fi 1.50 + echo -n "Starting $DESC: $NAME... " 1.51 + $DAEMON $OPTIONS 1.52 + [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE 1.53 + active_pidfile $PIDFILE $NAME 1.54 + status 1.55 + ;; 1.56 + stop) 1.57 + grep -qs $DAEMON /etc/inetd.conf && inactive_inetd 1.58 + if ! active_pidfile $PIDFILE $NAME ; then 1.59 + echo "$NAME is not running." 1.60 + exit 1 1.61 + fi 1.62 + echo -n "Stopping $DESC: $NAME... " 1.63 + kill `cat $PIDFILE` 1.64 + status 1.65 + ;; 1.66 + restart) 1.67 + grep -qs $DAEMON /etc/inetd.conf && exit 0 1.68 + if ! active_pidfile $PIDFILE $NAME ; then 1.69 + echo "$NAME is not running." 1.70 + exit 1 1.71 + fi 1.72 + echo -n "Restarting $DESC: $NAME... " 1.73 + kill `cat $PIDFILE` 1.74 + sleep 2 1.75 + $DAEMON $OPTIONS 1.76 + [ -f $PIDFILE ] || pidof $NAME | awk '{ print $1 }' > $PIDFILE 1.77 + active_pidfile $PIDFILE $NAME 1.78 + status 1.79 + ;; 1.80 +*) 1.81 + echo "" 1.82 + echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]" 1.83 + echo "" 1.84 + exit 1 1.85 + ;; 1.86 +esac 1.87 + 1.88 +exit 0