#!/bin/sh # # this script is under version control on gelfand.mdcc.cx # # the latest version should be in # $CVSROOT/mdcc.cx/djb/daemontools/script/svscan # # this script can be downloaded from http://mdcc.cx/~joostvb/daemontools/ # # $Id: svscan,v 1.7 2001/08/07 06:00:28 vanbaal Exp $ # # /etc/init.d/svscan Start and stop the svscan daemon. # # *** description *** # # svscan is a general-purpose service manager, handling # execution of daemons, and ensuring their operation. # # # *** how to manually stop and start a service: (e.g. dnscache) *** # # # cd /service/dnscache # # touch down # # svc -d . # (stop log if necessary); inspect status, doing a # # svstat . # restart it: (restart log, if necessary) # # rm down # # svc -u . # # # *** how to stop the entire suite *** # # (/etc/init.d/svscan won't stop everything, since we cannot get svscan's # pid in a reliable way) # # run /etc/init.d/svscan stop # send /usr/local/bin/svscan a KILL # run /etc/init.d/svscan exit # # *** see also *** # # more documentation is on http://cr.yp.to/daemontools.html # # *** author *** # # script based on # # Date: Tue, 11 Jul 2000 09:19:50 -0400 # From: Bennett Todd # To: tech_related@ip.pt # Cc: dns@list.cr.yp.to # Subject: Re: minor problem while actually installing dnscache # # a redhat style init script. # # Severely hacked by Joost van Baal. # # svdir=/service svscan=/usr/local/bin/svscan svsca=/usr/local/bin/svsca supervise=/usr/local/bin/supervise sv_touch () { echo "Touching ${1}/down..." touch ${1}/down [ -k ${1} ] && echo "Touching ${1}/log/down..." && touch ${1}/log/down } sv_down () { echo "Checking supervise status in ${1}..." svok ${1} || return echo "Stopping service `basename ${1}`..." svc -d ${1} [ -k ${1} ] && echo "Stopping service log `basename ${1}`..." && \ svc -d ${1}/log } sv_exit () { echo "Checking supervise status in ${1}..." svok ${1} || return echo "Stopping supervise service `basename ${1}`..." svc -x ${1} [ -k ${1} ] && echo "Stopping supervise service log `basename ${1}`..." && \ svc -x ${1}/log } sv_clean () { echo "Cleaning up down file in ${1}..." [ -f ${1}/down ] && rm ${1}/down echo "Cleaning up down file in ${1}/log..." [ -f ${1}/log/down ] && rm ${1}/log/down } sv_up () { echo "Checking supervise status in ${1}..." svok ${1} || { echo "supervise not running in ${1}, skipping" && return; } [ -k ${1} ] && echo "Starting service log `basename ${1}`..." && \ svc -u ${1}/log echo "Starting service `basename ${1}`..." svc -u ${1} } sv_stat () { echo "Checking supervise status in ${1}..." svok ${1} && echo -n "Status ${1}: " && svstat ${1} if [ -k ${1} ] then echo "Checking supervise status in ${1}/log..." svok ${1}/log || return echo -n "Status ${1}/log: " svstat ${1}/log fi } [ -x $svscan ] || exit 0 [ -d $svdir ] || exit 0 # our djb stuff is in /usr/local/bin PATH=$PATH:/usr/local/bin # See how we were called. case "$1" in start) for service in `ls $svdir` do sv_clean $svdir/$service done if ps -Ao args | grep -q $svsca'[n]' then echo -n "svscan seems to be running yet! " echo "$0 resume might do what you want." else # Start svscan. echo 'Starting svscan...' env - PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/sh \ -c "$svscan $svdir &" fi ;; stop|pause) for service in `ls $svdir` do sv_touch $svdir/$service sv_down $svdir/$service done ;; resume) for service in `ls $svdir` do sv_clean $svdir/$service sv_up $svdir/$service done ;; exit) if ps -Ao args | grep -q $svsca'[n]' then echo -n "svscan seems to be running still! " echo "First send svscan a KILL manually, after running $0 stop" exit 1 fi for service in `ls $svdir` do sv_exit $svdir/$service done ;; status) for service in `ls $svdir` do sv_stat $svdir/$service done ;; *) echo "Usage: svscan {start|stop|pause|resume|exit|status}" exit 1 esac