Package: runit Version: 2.1.2-35 Followup-For: Bug #943397 I'm attaching two patches for review; one thing that I'm still not sure about is the exit code range. $1 in the finish file can be run's exit code or the daemon's exit code. I'm using the wierd range 160-170 but is still possible that the exit code is overlapped with the one of some daemons, for example see smartd(8) 'EXIT STATUS' section. Do you have a better range to suggest?
Lorenzo -- System Information: Debian Release: bullseye/sid APT prefers unstable APT policy: (500, 'unstable'), (1, 'experimental') Architecture: amd64 (x86_64) Kernel: Linux 4.20.3-van (SMP w/4 CPU cores; PREEMPT) Kernel taint flags: TAINT_OOT_MODULE Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: runit (via /run/runit.stopit) Versions of packages runit depends on: ii libc6 2.29-3 ii sysuser-helper 1.3.3 Versions of packages runit recommends: ii runit-init 2.1.2-35 runit suggests no packages. -- Configuration Files: /etc/default/runit changed [not included] /etc/runit/3 changed [not included] -- no debconf information -- debsums errors found: debsums: changed file /lib/runit/invoke-run (from runit package) debsums: changed file /sbin/update-service (from runit package)
>From b1cc7e3521b1d13694bb9688705975870edbd707 Mon Sep 17 00:00:00 2001 From: Lorenzo Puliti <lorenzo.r...@gmail.com> Date: Mon, 4 Nov 2019 19:48:37 +0100 Subject: [PATCH 1/2] Add finish-default Add a finish-default file to be sourced from finish scripts Closes: #943397 --- debian/contrib/lib/finish-default | 32 +++++++++++++++++++++++++++++++ debian/runit.install | 1 + 2 files changed, 33 insertions(+) create mode 100644 debian/contrib/lib/finish-default diff --git a/debian/contrib/lib/finish-default b/debian/contrib/lib/finish-default new file mode 100644 index 0000000..bbc8955 --- /dev/null +++ b/debian/contrib/lib/finish-default @@ -0,0 +1,32 @@ +#!/bin/echo this script must be sourced, not executed. + +. /etc/default/runit +NAME=$(pwd | cut -f4 -d"/") + +trap 'if [ "$VERBOSE" = 1 ]; then echo "runsv: $NAME stopped"; fi' EXIT + +case $1 in + -1) + echo "runsv: ERROR $1 in $NAME: unexpected error or wrong sh syntax" + # no need to sv d service here, runsv will stop trying after the first attempt to start + ;; + + 161) + echo "runsv: ERROR $1 in $NAME: disabled by local settings" + sv d $NAME + exit 0 + ;; + + 162) + echo "runsv: ERROR $1 in $NAME: configtest or early setup failed" + sv d $NAME + exit 0 + ;; + + 170) + echo "runsv: ERROR $1 in $NAME: a runtime hard dependecy is missing" + sv d $NAME + exit 0 + ;; +esac + diff --git a/debian/runit.install b/debian/runit.install index 40a9466..3bdd592 100644 --- a/debian/runit.install +++ b/debian/runit.install @@ -23,3 +23,4 @@ debian/contrib/runlevel /lib/runit debian/sulogin/run /etc/runit/runsvdir/single/sulogin debian/contrib/lib/async-timeout /lib/runit debian/contrib/lib/run_sysv_scripts /lib/runit +debian/contrib/lib/finish-default /lib/runit -- 2.24.0
>From 642ffb914b6e7d67c723f7e620f3b9a404d7572e Mon Sep 17 00:00:00 2001 From: Lorenzo Puliti <lorenzo.r...@gmail.com> Date: Tue, 5 Nov 2019 23:49:58 +0100 Subject: [PATCH 2/2] Update invoke-run manpage for finish-default Update invoke-run manpage to account for finish-default file and special error codes. --- debian/contrib/man/invoke-run.5 | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/debian/contrib/man/invoke-run.5 b/debian/contrib/man/invoke-run.5 index 51b06a5..9fb7221 100644 --- a/debian/contrib/man/invoke-run.5 +++ b/debian/contrib/man/invoke-run.5 @@ -77,6 +77,98 @@ If both file and .BI "/etc/sv/" foo "/conf" directory define some variable, value from directory takes precedence. +.SH SPECIAL ERROR CODE +Looking in the +.I foo +service log it's possible to see messages in the form of +.IP "" 2 +runsv: ERROR [NNN] in foo: reason for the error +.PP +These messages don't come from runsv itself but from +.B invoke-run, +the run file or the finish file. The purpose of these message +is to detail a permanent failure condition that prevents +.I foo +service from being up. +For each +.I foo +service, possible errors and messages are: +.IP "" 2 +.B runsv: foo binary not installed +.PP +.IP "" 4 +this happens when the +.I foo +binary has been removed, but not purged. +.PP +.IP "" 2 +.B runsv: ERROR -1 in foo: unexpected error or wrong sh syntax +.PP +.IP "" 4 +this message comes from the finish file, but the exit code comes from +.BR runsv (8) +and is documented in its manpage. +.PP +.IP "" 2 +.B runsv: ERROR 161 in foo: disabled by local settings +.PP +.IP "" 4 +Some service specific setting prevent +.I foo +from starting; it's likely something in +.BI /etc/default/foo +.PP +.IP "" 2 +.B runsv: ERROR 162 in foo: configtest or early setup failed +.PP +.IP "" 4 +A configuration file of +.I foo +is malformed and the configtest failed; +.I foo +log may contain additional info from the test itself. +Otherwise the runscript has failed to do some setup that is essential to the +.I foo +service. +.PP +.IP "" 2 +.B runsv: ERROR 170 in foo: a runtime hard dependency is missing +.PP +.IP "" 4 +A dependency failed the check and can't be bring up; a list of dependencies of +.I foo +can be extracted with the following command +.PP +.IP "" 6 +.EX +grep 'exit 170' /etc/sv/foo/run | cut -d ' ' -f3 +.EE +.PP +.SH FINISH FILE AND FINISH-DEFAULT +Since version 2.1.2-36 the Debian runit package ships a +.BI /lib/runit/finish-default +file that contains code that can be shared across different services. +This file can be sourced inside the regular finish file of a service, +like the following example + +.EX + $ cat /etc/sv/foo/finish + #!/bin/sh + set -e +\ . /lib/runit/finish-default "$@" +.EE + +Services that need to put specific code into the finish file should do after +the line that sources finish-default. For each +.I foo +service, finish-default file sources +.BI /etc/default/runit, +export a +.BI NAME=foo +variable and defines special error codes as described in the previous section. +Also, in order to print a 'foo stopped' message at the very end of the finish file, +.BI EXIT +is trapped. .SH SEE ALSO .BR runsvdir (8), .BR dh_runit (1), -- 2.24.0