From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/760 Path: news.gmane.org!not-for-mail From: Charlie Brady Newsgroups: gmane.comp.sysutils.supervision.general Subject: Re: runit and lsb init script actions Date: Sun, 10 Apr 2005 13:00:18 -0400 (EDT) Message-ID: References: <20050410151610.26722.qmail@c94466ef4374af.315fe32.mid.smarden.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: sea.gmane.org 1113152292 17867 80.91.229.2 (10 Apr 2005 16:58:12 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 10 Apr 2005 16:58:12 +0000 (UTC) Cc: supervision@list.skarnet.org Original-X-From: supervision-return-996-gcsg-supervision=m.gmane.org@list.skarnet.org Sun Apr 10 18:58:08 2005 Return-path: Original-Received: from antah.skarnet.org ([212.85.147.14]) by ciao.gmane.org with smtp (Exim 4.43) id 1DKfkd-000084-Fz for gcsg-supervision@gmane.org; Sun, 10 Apr 2005 18:57:35 +0200 Original-Received: (qmail 7854 invoked by uid 76); 10 Apr 2005 17:00:43 -0000 Mailing-List: contact supervision-help@list.skarnet.org; run by ezmlm List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Archive: Original-Received: (qmail 7848 invoked from network); 10 Apr 2005 17:00:43 -0000 X-X-Sender: charlieb@e-smith.charlieb.ott.istop.com Original-To: Gerrit Pape In-Reply-To: <20050410151610.26722.qmail@c94466ef4374af.315fe32.mid.smarden.org> Xref: news.gmane.org gmane.comp.sysutils.supervision.general:760 X-Report-Spam: http://spam.gmane.org/gmane.comp.sysutils.supervision.general:760 On Sun, 10 Apr 2005, Gerrit Pape wrote: > Hi, one thing that has been requested for runit multiple times is lsb > compliance concerning 'init script' actions, see > > http://refspecs.freestandards.org/LSB_2.1.0/LSB-Core-generic/LSB-Core-generic.html#INISCRPTACT > > It seems to be quite possible to implement an lsb compliant interface > through a separate program that runs runsvctrl up, down, term, hup, ..., > depending on the command line arguments. For service daemons that don't > do the right thing on up, down, term, hup, ..., it's possible to > override the actions through the customized control scripts in > /control/. This separate program may be symlinked to > /etc/init.d/, or used as a wrapper, and maybe fall back to an > original /etc/init.d/ script in case the service doesn't run > under runit's supervision. > > What do you think? Here's a runit specific version I use under a RedHat based system: #!/bin/sh ########################################################################### # # System V style init script. # Relies on runit utilities to do the real work. # It is assumed that init scripts will be linked to this script. # ########################################################################### # Determine the service name and its service directory from $0 SERVICE=$(/bin/basename $0 | sed -e 's/^[SK][0-9][0-9]*//') SERVICE_DIR=/service/$SERVICE ########################################################################### # Source in the RedHat initscripts functions . /etc/rc.d/init.d/functions # The maximum amount of time to wait for a process to shut down, in seconds. WAITMAX=60 start() { /bin/echo -n "Starting $SERVICE:" dirs=$1 if [ -d $1/log ]; then dirs="$1/log $1" fi /usr/bin/runsvctrl u $dirs if [ $? -ne 0 ]; then failure "Starting $SERVICE" else success "Starting $SERVICE" fi /bin/echo } status() { /usr/bin/runsvstat $1 } stop() { /bin/echo -n "Stopping $SERVICE:" /usr/bin/svwaitdown -t $WAITMAX $1 if [ $? -ne 0 ]; then failure "Stopping $SERVICE" else success "Stopping $SERVICE" fi /bin/echo } # This function not only shuts the service down, but removes the /service # symlink and shuts down the logger. This should only be used during an # uninstall of the service in question. svdisable() { /bin/echo -n "Disabling $SERVICE:" stop $1 cd $1 && rm -f $1 dirs=. if [ -e log ]; then dirs="$dirs ./log" fi /usr/bin/runsvctrl d $dirs /usr/bin/runsvctrl x $dirs if [ $? -ne 0 ]; then failure "Disabling $SERVICE" else success "Disabling $SERVICE" fi /bin/echo } case $1 in restart) /usr/bin/runsvctrl t $SERVICE_DIR /usr/bin/runsvctrl u $SERVICE_DIR ;; sigalrm) /usr/bin/runsvctrl a $SERVICE_DIR ;; sigcont) /usr/bin/runsvctrl c $SERVICE_DIR ;; sighup) /usr/bin/runsvctrl h $SERVICE_DIR ;; sigusr1) /usr/bin/runsvctrl 1 $SERVICE_DIR ;; sigusr2) /usr/bin/runsvctrl 2 $SERVICE_DIR ;; sigint) /usr/bin/runsvctrl i $SERVICE_DIR ;; sigkill) /usr/bin/runsvctrl k $SERVICE_DIR ;; sigstop) /usr/bin/runsvctrl p $SERVICE_DIR ;; sigterm) /usr/bin/runsvctrl t $SERVICE_DIR ;; status) /usr/bin/runsvstat $SERVICE_DIR ;; start) start $SERVICE_DIR ;; stop) stop $SERVICE_DIR ;; svdisable) svdisable $SERVICE_DIR ;; *) echo "usage: $0 {start|stop|restart|status|sigalrm|sigcont|sighup|sigint|sigkill|sigstop|sigterm|sigusr1|sigusr2|svdisable}" ;; esac