supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* How to kill runsv, no matter what?
@ 2007-02-21 20:14 Daniel Clark
  2007-02-21 21:04 ` Daniel Clark
  0 siblings, 1 reply; 14+ messages in thread
From: Daniel Clark @ 2007-02-21 20:14 UTC (permalink / raw)
  To: supervision

I'm integrating runit support into bcfg2 [1], both as something bcfg2
can control, and as an encap [2] package [3]. I'm replacing
daemontools, as djb's annoying redistribution policies wouldn't allow
me to distribute Xen images or LiveCDs (as I patched daemontools since
there hasn't been a release in a very long time, but there have been
bugs).

I'm trying to get to a state where I can add and remove the runit
package without leaving any state behind (I'm using it for runsvdir,
not as an init replacement). When the package is removed, all of the
runit services should stop, and state about what services were started
is saved somewhere; on reinstall, that state should be reintroduced,
and any runit services should be restarted.

In theory this should be pretty trivial (assuming I am RTFMing
correctly); I think something like this in the removal stage:

test -d /usr/local/var/service/.disabled || mkdir
/usr/local/var/service/.disabled
mv /usr/local/var/service/* /usr/local/var/service/.disabled/ 2>/dev/null \
    || printf "No services to disable.\n"
printf "Waiting 7 seconds for runsv processes to die...\n"
sleep 7
# ... (Code that stops runsvdir) ...
for service in `ls /usr/local/etc/sv`; do
    test -d /usr/local/etc/sv/$service/supervise \
        && rm -rf /usr/local/etc/sv/$service/supervise
    test -d /usr/local/etc/sv/$service/log/supervise \
        && rm -rf /usr/local/etc/sv/$service/log/supervise
done

However in practice there are some services that continue to have a
"runsv" process even after I remove them from the directory "runsvdir"
is monitoring and wait >5 seconds. Below is an example of such a
service that refuses to die. With daemontools I had a script called
svrm that did this (below), but the same idiom doesn't seem to work
with runit/runsvdir. Am I doing something wrong, or is this a bug?

----------------------------------------------------------------------

root@pawn:/usr/local/etc/sv# cat bcfg2-client/run
#!/bin/sh
exec 2>&1
printf "*** exec /usr/local/bin/chpst -e
/usr/local/etc/default/bcfg2-client/env ./bcfg2-client.sh ...\n"
exec /usr/local/bin/chpst -e /usr/local/etc/default/bcfg2-client/env
./bcfg2-client.sh

----------------------------------------------------------------------

root@pawn:/usr/local/etc/sv# cat bcfg2-client/bcfg2-client.sh
#!/bin/sh

# note: variables provided from environment with chpst -e:
#       /usr/local/etc/default/bcfg2-client/env/OPTIONS
#       /usr/local/etc/default/bcfg2-client/env/RUN_INTERVAL_SECONDS

ENVDIR="/usr/local/etc/default/bcfg2-client/env"

# make sure we have options
if [ ! -f ${ENVDIR}/OPTIONS ]; then
    printf "WARNING: ${ENVDIR}/OPTIONS\n"
    printf "WARNING: does not exist. Using default of \"-q -v -d -n\"\n"
    OPTIONS="-q -v -d -n"
fi

# make sure we have a sleep variable
if [ "${RUN_INTERVAL_SECONDS}x" = "x" ]; then
    printf "WARNING: ${ENVDIR}/RUN_INTERVAL_SECONDS\n"
    printf "WARNING: does not exist or has no value.\n"
    printf "WARNING: Using default of 3600 seconds between runs.\n"
    RUN_INTERVAL_SECONDS=3600
fi

# loop forever
while :
do
    printf "*** starting /usr/local/bin/bcfg2 ${OPTIONS} ...\n"
    /usr/local/bin/bcfg2 ${OPTIONS}
    printf "*** sleeping ${RUN_INTERVAL_SECONDS} seconds ...\n"
    sleep ${RUN_INTERVAL_SECONDS}
done

exit 0

----------------------------------------------------------------------

<include_file name="bin/svrm" mode="0755"><![CDATA[
#!/bin/sh
# Remove a daemontools service
PATH=/command:$PATH
export PATH
if [ "${1}x" = "x" -o "${2}x" != "x" ]; then
    printf "Usage: svrm [SERVICE]\n"
    exit 1
fi
SERVICE="`basename ${1}`"
if [ ! -h "/service/$SERVICE" -a ! -f "/service/$SERVICE" ]; then
    printf "Service \"${SERVICE}\" not installed. Installed services:\n"
    svstat /service/*
    exit 1
else
    cd /service/$SERVICE
    REALDIR=`pwd -P`
    rm /service/$SERVICE
    svc -dx . log
    sleep 1
    test -f ${REALDIR}/supervise/status && rm ${REALDIR}/supervise/status
    test -d ${REALDIR}/supervise && rm -rf ${REALDIR}/supervise
    test -f ${REALDIR}/log/supervise/status && rm
${REALDIR}/log/supervise/status
    test -d ${REALDIR}/log/supervise && rm -rf ${REALDIR}/log/supervise
fi
exit 0
]]></include_file>

----------------------------------------------------------------------

[1] http://www.bcfg2.org
[2] http://www.encap.org
[3] http://www.bcfg2.org/browser/trunk/bcfg2/encap/src/encap-profiles/runit-1.7.2.ep

Thanks for any help,
-- 
Daniel Clark # http://dclark.us # http://opensysadmin.com


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

end of thread, other threads:[~2007-02-28 23:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-21 20:14 How to kill runsv, no matter what? Daniel Clark
2007-02-21 21:04 ` Daniel Clark
2007-02-23  3:51   ` Daniel Clark
2007-02-23 12:02     ` Laurent Bercot
2007-02-23 14:05     ` Gerrit Pape
2007-02-23 14:24       ` Alex Efros
2007-02-23 17:40         ` Daniel Clark
2007-02-23 17:32       ` Daniel Clark
2007-02-23 17:39         ` Paul Jarc
2007-02-23 17:46           ` Daniel Clark
2007-02-23 17:59             ` Paul Jarc
2007-02-23 18:25               ` Daniel Clark
2007-02-23 18:32                 ` Paul Jarc
2007-02-28 23:24                   ` Daniel Clark

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).