Package: init-system-helpers
Version: 1.66
Followup-For: Bug #924132

Dear Maintainer,

Kindly ask if is there any progress of this bug. It will be very grateful for
adding support of runit in init-system-helpers as it will make use runit as
system init a bit easier.

I just start to use runit, so please correct me if I am wrong. Honestly it
seems to me that runit's support for sysvinit is poor, making use runit as
system init hard. Yes, runit-init will start scripts under /etc/rc2.d/ for me
as done in /etc/runit/2 during boot. But after boot completes, sv status/up/down
is not working for scripts under /etc/init.d/. Maybe it is better to solve this
by improving support for sysvinit in runit. But if this can be easily done in
init-system-helpers, it may still be a choice. And doing this in
init-system-helpers
has a benefit that have a consistent interface between different init. When I
used systemd as init, I still was used to use `service start/stop' to manage
system daemons. It will be thankful to still use that when use runit as init.

So really please consider adding support for runit in this package.

Regarding to the merge requests by Lorenzo Puliti[1], I have applied it into
and rebuild the init-system-helpers package. It helps me immediately. Although
maybe more polish(or update) is still needed. The first one is that the patch
only consider service under /etc/sv/. Under /etc/service/, I see there are
symlinks to not only /etc/sv/*, but also /usr/share/runit/sv.current/*.
/usr/share/runit/sv.current/* is provided by the runit-services
package and may also
be treated. Another one is `service --status-all' now only shows runit services.
It will better to show both runit services and sysvinit services. This
may be done
by the following changes:

--- a/script/service
+++ b/script/service
@@ -79,6 +87,26 @@
               functions | halt | killall | single| linuxconf| kudzu)
                   ;;
               *)
+                if [ -n "$is_runit" ]; then
+                   runit_service=
+                   if [ -d "/etc/sv/${SERVICE}" ]; then
+                     runit_service="/etc/sv/${SERVICE}"
+                   elif [ -d "/usr/share/runit/sv.current/${SERVICE}" ]; then
+                     runit_service="/usr/share/runit/sv.current/${SERVICE}"
+                   fi
+
+                   if [ -n "$runit_service" ]; then
+                     sv status "$runit_service" \
+                       | sed -e 's|run: /etc/sv/| \[ + ] run: |' \
+                             -e 's|down: /etc/sv/| \[ - ] down: |' \
+                             -e 's|fail: /etc/sv/|disabled: |' \
+                             -e 's|run: /usr/share/runit/sv.current/|
\[ + ] run: |' \
+                             -e 's|down:
/usr/share/runit/sv.current/| \[ - ] down: |' \
+                             -e 's|fail:
/usr/share/runit/sv.current/|disabled: |'
+                     continue
+                   fi
+                fi
+
                 if ! is_ignored_file "${SERVICE}" \
             && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
                         out=$(env -i LANG="$LANG"
LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC"
LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY"
LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME"
LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE"
LC_MEASUREMENT="$LC_MEASUREMENT"
LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH"
TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)

instead of the original changes:

--- a/script/service
+++ b/script/service
@@ -73,6 +80,11 @@ while [ $# -gt 0 ]; do
        ;;
     *)
        if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
+          if [ -n "$is_runit" ]; then
+             exec sv status /etc/sv/* \
+             | sed -e 's|run: /etc/sv/|\[ + ] run: |' -e 's|down:
/etc/sv/|\[ - ] down: |' -e 's|fail: /etc/sv/|disabled: |'
+             exit 0
+          fi
           cd ${SERVICEDIR}
           for SERVICE in * ; do
             case "${SERVICE}" in

I attach the debdiff between my build against 1.66 if it will help.

[1]: https://salsa.debian.org/debian/init-system-helpers/merge_requests/10

Regards,
Jun Mo

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

Kernel: Linux 6.7.12-amd64 (SMP w/2 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE,
TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8),
LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: runit (via /run/runit.stopit)
LSM: AppArmor: enabled

Versions of packages init-system-helpers depends on:
ii  runit-helper              2.16.2
ii  usr-is-merged             39
ii  usrmerge [usr-is-merged]  39

init-system-helpers recommends no packages.

init-system-helpers suggests no packages.

Versions of packages init-system-helpers is related to:
ii  insserv  1.24.0-2

-- no debconf information
diff -Nru init-system-helpers-1.66/debian/changelog 
init-system-helpers-1.66/debian/changelog
--- init-system-helpers-1.66/debian/changelog   2023-11-27 04:42:28.000000000 
+0800
+++ init-system-helpers-1.66/debian/changelog   2024-05-04 16:35:27.000000000 
+0800
@@ -1,3 +1,13 @@
+init-system-helpers (1.66-0local1) unstable; urgency=low
+
+  * Local package.
+  * Add support for runit-init from
+    https://salsa.debian.org/debian/init-system-helpers/-/merge_requests/10
+    with modifications including support /usr/share/runit/sv.current/ and 
+    `service --status-all' also show status for sysvinit.
+
+ -- Roy Clark (kralcyor) <royclark...@gmail.com>  Sat, 04 May 2024 16:35:27 
+0800
+
 init-system-helpers (1.66) unstable; urgency=medium
 
   [ Samuel Thibault ]
diff -Nru init-system-helpers-1.66/debian/control 
init-system-helpers-1.66/debian/control
--- init-system-helpers-1.66/debian/control     2023-11-24 20:34:19.000000000 
+0800
+++ init-system-helpers-1.66/debian/control     2024-05-04 16:35:12.000000000 
+0800
@@ -22,7 +22,8 @@
 Priority: required
 Essential: yes
 Multi-Arch: foreign
-Depends: ${misc:Depends},
+Depends: runit-helper (>= 2.8.15),
+         ${misc:Depends},
          ${perl:Depends},
          usrmerge | usr-is-merged,
 Description: helper tools for all init systems
diff -Nru init-system-helpers-1.66/debian/patches/invoke-rc.d.patch 
init-system-helpers-1.66/debian/patches/invoke-rc.d.patch
--- init-system-helpers-1.66/debian/patches/invoke-rc.d.patch   1970-01-01 
08:00:00.000000000 +0800
+++ init-system-helpers-1.66/debian/patches/invoke-rc.d.patch   2024-05-04 
16:35:27.000000000 +0800
@@ -0,0 +1,43 @@
+From cfced20b1f3a997c1c443f104151d4d8c74bd985 Mon Sep 17 00:00:00 2001
+From: Lorenzo Puliti <lorenzo.r...@gmail.com>
+Date: Tue, 19 Feb 2019 15:37:44 +0100
+Subject: [PATCH 2/4] Add support for runit into invoke-rc.d script
+
+When init is runit and a runscript in /etc/sv exists, the invoke-rc.d
+action will be a no-op, as the requested action will be handled by
+dh-runit and runit-helper.
+If there is no runscript, invoke-rc.d will fallback on sysv script.
+---
+ script/invoke-rc.d | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+--- a/script/invoke-rc.d
++++ b/script/invoke-rc.d
+@@ -39,6 +39,7 @@
+ RC=
+ is_systemd=
+ is_openrc=
++is_runit=
+ SKIP_SYSTEMD_NATIVE=
+ 
+ # Shell options
+@@ -279,6 +280,8 @@
+     UNIT="${INITSCRIPTID%.sh}.service"
+ elif test -f /run/openrc/softlevel ; then
+     is_openrc=1
++elif test -f /run/runit.stopit ; then
++    is_runit=1
+ elif test ! -f "${INITDPREFIX}${INITSCRIPTID}" ; then
+     ## Verifies if the given initscript ID is known
+     ## For sysvinit, this error is critical
+@@ -540,6 +543,10 @@
+                 esac
+           elif [ -n "$is_openrc" ]; then
+               rc-service "${INITSCRIPTID}" "${saction}" && exit 0
++            elif [ -n "$is_runit" ] && [ -d "/etc/sv/${INITSCRIPTID}" ]; then
++              # no-op for runit native services as invoke-rc.d style actions
++              # are handled by dh-runit and runit-helper
++              exit 0
+           else
+               "${INITDPREFIX}${INITSCRIPTID}" "${saction}" "$@" && exit 0
+           fi
diff -Nru init-system-helpers-1.66/debian/patches/series 
init-system-helpers-1.66/debian/patches/series
--- init-system-helpers-1.66/debian/patches/series      1970-01-01 
08:00:00.000000000 +0800
+++ init-system-helpers-1.66/debian/patches/series      2024-05-04 
16:35:27.000000000 +0800
@@ -0,0 +1,3 @@
+invoke-rc.d.patch
+service.patch
+update-rc.d.patch
diff -Nru init-system-helpers-1.66/debian/patches/service.patch 
init-system-helpers-1.66/debian/patches/service.patch
--- init-system-helpers-1.66/debian/patches/service.patch       1970-01-01 
08:00:00.000000000 +0800
+++ init-system-helpers-1.66/debian/patches/service.patch       2024-05-04 
16:35:27.000000000 +0800
@@ -0,0 +1,111 @@
+From f11c934f277bd977a899c199b9369740e2e9f148 Mon Sep 17 00:00:00 2001
+From: Lorenzo Puliti <lorenzo.r...@gmail.com>
+Date: Tue, 19 Feb 2019 15:07:16 +0100
+Subject: [PATCH] Add support for runit into service script
+
+When init is runit and a runscript in /etc/sv/ exists, the service
+script will act as a wrapper for sv.
+If the service is disabled the script will exit with an error; if no
+runscript exists the script will fallback on sysv init script.
+---
+ script/service | 46 +++++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 43 insertions(+), 3 deletions(-)
+
+--- a/script/service
++++ b/script/service
+@@ -49,6 +49,10 @@
+ SERVICEDIR="/etc/init.d"
+ OPTIONS=
+ is_systemd=
++is_runit=
++# runit service dir
++RUNDIR="/etc/sv"
++RUNDIR2="/usr/share/runit/sv.current"
+ 
+ 
+ if [ $# -eq 0 ]; then
+@@ -60,6 +64,10 @@
+    is_systemd=1
+ fi
+ 
++if [ -f /run/runit.stopit ]; then
++   is_runit=1
++fi
++
+ cd /
+ while [ $# -gt 0 ]; do
+   case "${1}" in
+@@ -79,6 +87,26 @@
+               functions | halt | killall | single| linuxconf| kudzu)
+                   ;;
+               *)
++                if [ -n "$is_runit" ]; then
++                   runit_service=
++                   if [ -d "/etc/sv/${SERVICE}" ]; then
++                     runit_service="/etc/sv/${SERVICE}"
++                   elif [ -d "/usr/share/runit/sv.current/${SERVICE}" ]; then
++                     runit_service="/usr/share/runit/sv.current/${SERVICE}"
++                   fi
++
++                   if [ -n "$runit_service" ]; then
++                     sv status "$runit_service" \
++                       | sed -e 's|run: /etc/sv/| \[ + ] run: |' \
++                             -e 's|down: /etc/sv/| \[ - ] down: |' \
++                             -e 's|fail: /etc/sv/|disabled: |' \
++                             -e 's|run: /usr/share/runit/sv.current/| \[ + ] 
run: |' \
++                             -e 's|down: /usr/share/runit/sv.current/| \[ - ] 
down: |' \
++                             -e 's|fail: 
/usr/share/runit/sv.current/|disabled: |'
++                     continue
++                   fi
++                fi
++
+                 if ! is_ignored_file "${SERVICE}" \
+                   && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+                         out=$(env -i LANG="$LANG" LANGUAGE="$LANGUAGE" 
LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" 
LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" 
LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" 
LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" 
LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" 
TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
+@@ -106,9 +134,9 @@
+           exit 0
+        elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
+           SERVICE="${1}"
+-          # On systems using systemd, we just perform a normal restart:
+-          # A restart with systemd is already a full restart.
+-          if [ -n "$is_systemd" ]; then
++          # On systems using systemd or runit, we just perform a normal 
restart:
++          # A restart with systemd or runit is already a full restart.
++          if [ -n "$is_systemd" -o -n "$is_runit" ]; then
+              ACTION="restart"
+           else
+              if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+@@ -213,5 +241,33 @@
+    esac
+ fi
+ 
++#Runit-init
++# Only perform ${ACTION} when there is a runscript for
++# the service and ${SERVICE} is enabled.
++# If the service is disabled print a message
++# and do not perform ${ACTION}
++# If there is no runscript at all fallback on sysv.
++if [ -n "$is_runit" ] && [ -d "${RUNDIR}/${SERVICE}" ] || [ -d 
"${RUNDIR2}/${SERVICE}" ]; then
++   case "${ACTION}" in
++      status)
++        if test -h /etc/service/"${SERVICE}"; then
++            exec sv "${ACTION}" "${SERVICE}"
++        else
++            echo "Service ${SERVICE} is disabled"
++            exit 0
++        fi
++        ;;
++      *)
++        if test -h /etc/service/"${SERVICE}"; then
++            exec sv "${ACTION}" "${SERVICE}"
++        else
++            echo "Can't ${ACTION} ${SERVICE}, the service is disabled"
++            exit 1
++        fi
++        ;;
++   esac
++fi
++
++
+ update_openrc_started_symlinks
+ run_via_sysvinit
diff -Nru init-system-helpers-1.66/debian/patches/update-rc.d.patch 
init-system-helpers-1.66/debian/patches/update-rc.d.patch
--- init-system-helpers-1.66/debian/patches/update-rc.d.patch   1970-01-01 
08:00:00.000000000 +0800
+++ init-system-helpers-1.66/debian/patches/update-rc.d.patch   2024-05-04 
16:35:27.000000000 +0800
@@ -0,0 +1,103 @@
+From 7f5535a655ec8e361ab9c8e1f0d92a2fa425d2e4 Mon Sep 17 00:00:00 2001
+From: Lorenzo Puliti <lorenzo.r...@gmail.com>
+Date: Thu, 21 Feb 2019 11:38:09 +0100
+Subject: [PATCH 3/4] Add support for runit to update-rc.d script
+
+Add a 'sub_make_runit_links' that links (enable) or
+unlinks (disable) a runit service in the default rundir.
+Also add runit to the end of the init sequence.
+Defaults, Defaults-disabled and Purge are no-op since
+are handled by dh-runit in maintscript
+---
+ script/update-rc.d | 54 ++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 54 insertions(+)
+
+--- a/script/update-rc.d
++++ b/script/update-rc.d
+@@ -99,6 +99,12 @@
+     }
+ }
+ 
++sub runit_force_rescan {
++    if (-f "/run/runit.stopit") {
++        system("kill", "-SIGALRM", "1");
++    }
++}
++
+ # Creates the necessary links to enable/disable a SysV init script (fallback 
if
+ # no insserv/rc-update exists)
+ sub make_sysv_links {
+@@ -185,6 +191,42 @@
+     }
+ }
+ 
++# Create/delete links to enable/disable the service in runit.
++# We only do this in the default rundir
++# defaults, defaults-disabled and remove are no-op; enabling, disabling
++# and purge in maintscript is a job for dh-runit
++# enable: link as /etc/service/$scriptname
++# disable: link as /etc/service/.$scriptname
++sub make_runit_links {
++    my ($scriptname, $action) = @_;
++
++    my $service_dir;
++    # no-op if there is no runit service installed
++    if (-d "/etc/sv/$scriptname") {
++        $service_dir = "/etc/sv/$scriptname";
++    } elsif (-d "/usr/share/runit/sv.current/$scriptname") {
++        $service_dir = "/usr/share/runit/sv.current/$scriptname";
++    } else {
++        return;
++    }
++
++    # enable the service
++    if ("enable" eq $action) {
++        if (-e "/etc/runit/runsvdir/default/.$scriptname") {
++            unlink("/etc/runit/runsvdir/default/.$scriptname");
++        }
++        symlink("$service_dir", "/etc/runit/runsvdir/default/$scriptname");
++    }
++
++    # disable the service
++    if ("disable" eq $action) {
++        if (-e "/etc/runit/runsvdir/default/$scriptname") {
++            unlink("/etc/runit/runsvdir/default/$scriptname");
++        }
++        symlink("$service_dir", "/etc/runit/runsvdir/default/.$scriptname");
++    }
++}
++
+ sub create_sequence {
+     my $force = (@_);
+     my $insserv = "$dpkg_root/usr/lib/insserv/insserv";
+@@ -325,6 +367,22 @@
+                openrc_rlconv(@toggle_lvls))
+     };
+ 
++    my $runit = {};
++    $runit->{remove} = sub {
++        runit_force_rescan;
++    };
++    $runit->{defaults} = sub {
++        runit_force_rescan;
++    };
++    $runit->{defaults_disabled} = sub {
++        runit_force_rescan;
++    };
++    $runit->{toggle} = sub {
++        my ($action, $scriptname) = (shift, shift);
++        make_runit_links($scriptname, $action);
++        runit_force_rescan;
++    };
++
+     my @sequence;
+     if ($insserv_installed) {
+         push @sequence, $sysv_insserv;
+@@ -338,6 +396,7 @@
+         push @sequence, $openrc;
+     }
+     push @sequence, $systemd;
++    push @sequence, $runit;
+ 
+     return @sequence;
+ }
diff -Nru init-system-helpers-1.66/debian/source/format 
init-system-helpers-1.66/debian/source/format
--- init-system-helpers-1.66/debian/source/format       2021-11-01 
22:05:55.000000000 +0800
+++ init-system-helpers-1.66/debian/source/format       2024-05-04 
16:34:10.000000000 +0800
@@ -1 +1 @@
-3.0 (native)
+3.0 (quilt)

Reply via email to