supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* runit and lsb init script actions
@ 2005-04-10 15:15 Gerrit Pape
  2005-04-10 17:00 ` Charlie Brady
  2005-04-19 22:05 ` Csillag Tamás
  0 siblings, 2 replies; 4+ messages in thread
From: Gerrit Pape @ 2005-04-10 15:15 UTC (permalink / raw)


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
<service>/control/.  This separate program may be symlinked to
/etc/init.d/<service>, or used as a wrapper, and maybe fall back to an
original /etc/init.d/<service> script in case the service doesn't run
under runit's supervision.

What do you think?

Thanks, Gerrit.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: runit and lsb init script actions
  2005-04-10 15:15 runit and lsb init script actions Gerrit Pape
@ 2005-04-10 17:00 ` Charlie Brady
  2005-04-18 19:17   ` Gerrit Pape
  2005-04-19 22:05 ` Csillag Tamás
  1 sibling, 1 reply; 4+ messages in thread
From: Charlie Brady @ 2005-04-10 17:00 UTC (permalink / raw)
  Cc: supervision


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
> <service>/control/.  This separate program may be symlinked to
> /etc/init.d/<service>, or used as a wrapper, and maybe fall back to an
> original /etc/init.d/<service> 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: runit and lsb init script actions
  2005-04-10 17:00 ` Charlie Brady
@ 2005-04-18 19:17   ` Gerrit Pape
  0 siblings, 0 replies; 4+ messages in thread
From: Gerrit Pape @ 2005-04-18 19:17 UTC (permalink / raw)


On Sun, Apr 10, 2005 at 01:00:18PM -0400, Charlie Brady wrote:
> 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
> ><service>/control/.  This separate program may be symlinked to
> >/etc/init.d/<service>, or used as a wrapper, and maybe fall back to an
> >original /etc/init.d/<service> script in case the service doesn't run
> >under runit's supervision.

> Here's a runit specific version I use under a RedHat based system:

Yes, this is the link approach, looks good.  I'm still thinking about
the wrapper; Debian uses an invoke-rc.d program to call init scripts on
package installation, which supports a user defined policy.  In any case
this needs documentation, a man page, and maybe an 'lsb init script
actions' page.

> # Determine the service name and its service directory from $0
> 
> SERVICE=$(/bin/basename $0 | sed -e 's/^[SK][0-9][0-9]*//')

SERVICE=${0##*/}
SERVICE=${SERVICE#[SK][0-9][0-9]}

>     *)
>         echo "usage: $0 
>         {start|stop|restart|status|sigalrm|sigcont|sighup|sigint|sigkill|sigstop|sigterm|sigusr1|sigusr2|svdisable}"
>         ;;

I don't think all these options should be supported, just the ones the
lsb documents.  runit services still should be controlled through the
runsvctrl program.

Thanks, Gerrit.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: runit and lsb init script actions
  2005-04-10 15:15 runit and lsb init script actions Gerrit Pape
  2005-04-10 17:00 ` Charlie Brady
@ 2005-04-19 22:05 ` Csillag Tamás
  1 sibling, 0 replies; 4+ messages in thread
From: Csillag Tamás @ 2005-04-19 22:05 UTC (permalink / raw)


On 04/10, 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
> <service>/control/.  This separate program may be symlinked to
> /etc/init.d/<service>, or used as a wrapper, and maybe fall back to an
> original /etc/init.d/<service> script in case the service doesn't run
> under runit's supervision.
> 
> What do you think?
> 
> Thanks, Gerrit.

I made similar script as Charlie Brady's, but mine is a bit simpler.

#! /bin/sh

NAME=someservicename

case "$1" in
  start)
        echo -n "Starting $NAME"
        /usr/bin/runsvctrl u /service/$NAME
        echo "."
        ;;
  stop)
        echo -n "Stopping $NAME"
        /usr/bin/runsvctrl d /service/$NAME
        echo "."
        ;;
  restart)
        echo -n "Restarting $NAME"
        /usr/bin/runsvctrl t /service/$NAME
        echo "."
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}" >&2
        exit 1
        ;;
esac

exit 0

I use this one in Debian so if I upgrade, it can start/stop the services as needed.
(As you can see this is a minimalist script.)

The only problem which I see that runit is in /usr/bin and as a base system utility
it should be in /sbin or /bin (like init).

What do you think?

-- 
"Real programmers can write assembly code in any language."
                                              -- Larry Wall

cstamas


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-04-19 22:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-10 15:15 runit and lsb init script actions Gerrit Pape
2005-04-10 17:00 ` Charlie Brady
2005-04-18 19:17   ` Gerrit Pape
2005-04-19 22:05 ` Csillag Tamás

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).