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

[Thu, 07 Nov 2019 00:30:45] Dmitry Bogatov <kact...@disroot.org>

>> +            echo "runsv: ERROR $1 in $NAME: unexpected error or wrong sh 
>> syntax"
>> ....
>
>Are you sure about "wrong sh syntax" part?

You are right, this is very inaccurate. Just for the records, I've made some 
tests:

* chmod -x /etc/sv/foo/run  --> exit 111

* mispelled 'invoke-run' in run's shebang --> exit 127

* invoke-run exits before executing run's file code --> exit -1

haven't find other case where it exit -1 for now, so i have reworded to

'runsv: ERROR $1 in $NAME: runscript didn't exit normally'

Patches that apply you review are attached

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 36efd3382ed5908d1f53e8ba38193aab4e38e157 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 | 35 +++++++++++++++++++++++++++++++
 debian/runit.install              |  1 +
 2 files changed, 36 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..5607c45
--- /dev/null
+++ b/debian/contrib/lib/finish-default
@@ -0,0 +1,35 @@
+#!/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 f1cb3095e88293e715d320cc36bbbd333b8531f5 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 | 93 +++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/debian/contrib/man/invoke-run.5 b/debian/contrib/man/invoke-run.5
index 51b06a5..7d44e85 100644
--- a/debian/contrib/man/invoke-run.5
+++ b/debian/contrib/man/invoke-run.5
@@ -77,6 +77,99 @@ 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; a list of dependencies of
+.I foo
+can be found in the run file, looking for lines like
+.PP
+.IP "" 6
+.EX
+sv start dep1  &&  sv check dep1  ||  exit 170
+.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, 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