Package: runit
Version: 2.1.2-45
Severity: wishlist
Hi,
Back in 2012 I sent Gerrit a start-stop-daemon.runit script (see
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=678985) that could be used
as a drop-in replacement for the real start-stop-daemon. It's a fairly
feature complete wrapper around the real start-stop-daemon that manages
runit services if they are present and passes calls to the real
start-stop-daemon if they are not.
I dpkg-divert /sbin/start-stop-daemon to /sbin/start-stop-daemon.real on all
my systems and install this script as /sbin/start-stop-daemon.
This way, initscript work transparently whether a service is managed by
runit or not. Without this script, care must be taken to avoid the real
start-stop-daemon starting daemons like e.g. ntpd or smartd alongside a
runit-managed instance.
The script used to be included in runit under /usr/share/doc until Dmitry
removed in 2016 because it was "unused".
I think it can be useful even if the package doesn't use it explicitly, but
a case could be made for runit to perform this diversion on install and ship
my script as /sbin/start-stop-daemon.
The only drawback (that I can see) is that this would introduce a dependency
on zsh, because that's what I wrote the script in. Maybe Suggests: zsh, make
installing my script both optional and contingent on zsh being present? (Of
course, people could still shoot themselves in the foot by removing zsh
afterwards. Can dpkg run a trigger when zsh is uninstalled?)
I'm attaching the current version of the script, which contains some
improvements over the 2012 version.
András
--
Government corruption is always reported in the past tense.
#!/bin/zsh
#
# This script is intended to wrap start-stop-daemon. It will call the
# original start-stop-daemon with the supplied arguments unless the daemon
# to be started appears to exist as a runit service, in which case it will
# map the start-stop-daemon call to an sv(8) call.
#
# Copyright 2012-2022 András Korn.
#
# Licensed under the GPL v3, or, at your option, under the same license as
# the runit package.
# If called by non-root user, fall back to original start-stop-daemon
# unconditionally
[[ $UID -gt 0 ]] && exec /sbin/start-stop-daemon.real $@
set -A args $@
SVDIR=${SVDIR:-/etc/service}
unset mode signal exec timeout startas testmode oknodo quiet verbose command
svstat candidates
oknodo=0
quiet=0
typeset -U candidates
while [[ -n "$1" ]]; do
case "$1" in
-S|--start) mode=start;;
-K|--stop) mode=stop;;
-T|--status)mode=status;;
-H|--help|-V|--version) exec /sbin/start-stop-daemon.real
$args;;
-x|--exec) shift; exec="$1";
candidates=($candidates ${1:t});;
-s|--signal)shift; signal=$1;;
--signal=*) signal="${1/--signal=/}";;
-R|--retry) shift; timeout="$1";;
--retry=*) timeout="${1/--retry=/}";;
-a|--startas) shift; startas="$1"
candidates=($acndidates ${1:t});;
-t|--test) testmode=1;;
-o|--oknodo)oknodo=1;;
-q|--quiet) quiet=1; exec >/dev/null;;
-v|--verbose) verbose=1;;
-m|--make-pidfile) make_pidfile=1;;
--remove-pidfile) remove_pidfile=1;;
-n|--name) shift;
candidates=($candidates $1);;
-p|--pidfile) shift; pidfile="$1";
candidates=($candidates ${1:t:r});;
--pidfile=*)pidfile="${1#--pidfile=}";
candidates=($candidates ${1:t:r});;
-u|--user|-g|--group|--pid|--ppid|-c|--chuid|-r|--chroot|-d|--chdir|-O|--output|-N|--nicelevel|-P|--procsched|-I|--iosched|-k|--umask)
shift;; # ignored
-b|--background|--nicelevel=*|--procsched=*|--iosched=*|--umask=*|-C|--no-close)
:;; # ignored
--notify-wait) echo "Warning: this version of
start-stop-daemon.runit ignores --notify-wait." >&2;;
--notify-timeout) echo "Warning: this version of
start-stop-daemon.runit ignores --notify-timeout." >&2;;
--) break;; # What follows is args to the
daemon. Avoid parsing those accidentally.
*) command="$1"; break;; # Assume the
previous was the last option; the rest is the name of the daemon plus args, of
which we only care about the daemon.
esac
shift
done
# returns success if $1 appears to be the name of a runit service
function issvname() {
[[ -d "$SVDIR/$1/supervise/." ]] && return 0
# 'supervise' could still be a symlink to a directory that doesn't
exist yet
[[ -L