Package: runit
Version: 2.1.2-35
Followup-For: Bug #943397

Dmitry Bogatov <kact...@disroot.org> wrote:

> Can you please elaborate on this case? How could runsv(1) know whether
> "run" file was read or not?

I've probably put in a way that is misleading: I don't know how/if runsv
knows whether run file was read.
You can reproduce the -1 exit code by moving away the meta file in
/usr/share/runit/meta/${service}/installed
for any service that has runit support already merged.
My guess is that this holds true for any case where invoke-run exits,
like in "noreplace", but I've not tested.

[ updated patches attached ]

Lorenzo


-- System Information:
Debian Release: bullseye/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 5.3.0-2-amd64 (SMP w/4 CPU cores)
Kernel taint flags: TAINT_UNSIGNED_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-5
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 d59f3dd0c5d6ff5fe005bc13bd09da1e3df4686f 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 | 34 +++++++++++++++++++++++++++++++
 debian/runit.install              |  1 +
 2 files changed, 35 insertions(+)
 create mode 100755 debian/contrib/lib/finish-default

diff --git a/debian/contrib/lib/finish-default 
b/debian/contrib/lib/finish-default
new file mode 100755
index 0000000..5cabbe4
--- /dev/null
+++ b/debian/contrib/lib/finish-default
@@ -0,0 +1,34 @@
+#!/bin/echo this script must be sourced, not executed.
+set -e
+
+. /etc/default/runit
+NAME=${PWD##*/}
+
+if [ "${VERBOSE:-0}" != 0 ] ; then
+       trap "echo runsv: $NAME stopped" EXIT
+fi
+
+case $1 in
+(-1)
+       echo "runsv: ERROR $1 in $NAME: runscript didn't exit normally"
+       # no need to sv d service here, runsv will stop trying after the first 
attempt
+       ;;
+
+(161)
+       echo "runsv: WARNING for $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..78b1307 100644
--- a/debian/runit.install
+++ b/debian/runit.install
@@ -22,4 +22,5 @@ debian/contrib/shutdown             /lib/runit
 debian/contrib/runlevel             /lib/runit
 debian/sulogin/run                  /etc/runit/runsvdir/single/sulogin
 debian/contrib/lib/async-timeout    /lib/runit
+debian/contrib/lib/finish-default    /lib/runit
 debian/contrib/lib/run_sysv_scripts /lib/runit
-- 
2.24.0

>From 3338c1c72043e6062fc637bd99ee4a4fb738da36 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 | 88 +++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/debian/contrib/man/invoke-run.5 b/debian/contrib/man/invoke-run.5
index 51b06a5..80d38d0 100644
--- a/debian/contrib/man/invoke-run.5
+++ b/debian/contrib/man/invoke-run.5
@@ -77,6 +77,94 @@ 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 package containing
+.I foo
+binary has been removed, but not purged.
+.PP
+.IP "" 2
+.B runsv: ERROR -1 in foo: runscript didn't exit normally
+.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: WARNING for 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.
+Alternatively 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; to know dependencies of
+.I foo
+service look for "sv start" in "run" script.
+.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, when VERBOSE mode is on,
+.BI EXIT
+is trapped so that a 'foo stopped' message gets printed
+at the very end of the finish file.
 .SH SEE ALSO
 .BR runsvdir (8),
 .BR dh_runit (1),
-- 
2.24.0

Reply via email to