On Wed, 8 Oct 2025 09:38:15 +0100 Andrew Bower <[email protected]> wrote:
> > Sorry I don't think I got round to testing your second version of this > solution. I'll report back if I do. I'm attaching the patch here, it's no longer on salsa due to my bad habit of rebasing on next branch.
>From 32e72b882a2a29a2f33eba2bfa618738c0fdf59e Mon Sep 17 00:00:00 2001 From: Lorenzo Puliti <[email protected]> Date: Sat, 20 Sep 2025 16:30:49 +0200 Subject: [PATCH 1/2] start socklog on systems without runit-init try to handle actions for enable, start/restart in postinstall; disable (and stop) services in prerm; then perform a runsvdir forced rescan to reduce chance of races in posrtrm. try to handle purge actions in postrm. --- debian/socklog-run.postinst | 29 +++++++++++++++++++++++++++++ debian/socklog-run.postrm | 19 +++++++++++++++++++ debian/socklog-run.prerm | 26 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 debian/socklog-run.postinst create mode 100644 debian/socklog-run.postrm create mode 100644 debian/socklog-run.prerm diff --git a/debian/socklog-run.postinst b/debian/socklog-run.postinst new file mode 100644 index 0000000..78349cd --- /dev/null +++ b/debian/socklog-run.postinst @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +#DEBHELPER# + +#enable socklog-unix and socklog-klog when runit is not init, see #1112379 +if [ ! -f /etc/runit/stopit ] && [ "$1" = "configure" ] && [ -z "$DPKG_ROOT" ]; then + if [ -x /usr/sbin/policy-rc.d ]; then #policy-rc.d layer, likely the installer or a build chroot + set +e ; /usr/sbin/policy-rc.d ; rc=$? ; set -e + if [ "$rc" = "101" ]; then + echo "socklog-unix; socklog-klog: action denied by policy-rc.d" && exit 0 + fi + fi + #enable the service; this will also start the service + update-service defaults /etc/sv/socklog-unix || echo "error: failed to enable socklog-unix" + update-service defaults /etc/sv/socklog-klog || echo "error: failed to enable socklog-klog" + # restart on upgrade + if [ -n "$2" ] && pidof runsvdir > /dev/null ; then + #upgrade --> raction=restart + klogstat=$(cat /etc/service/socklog-klog/supervise/stat) || klogstat= + sockstat=$(cat /etc/service/socklog-unix/supervise/stat) || sockstat= + if [ "$klogstat" = 'run' ] ; then + sv restart /etc/service/socklog-klog || echo "warning: failed to restart socklog-klog" + fi + if [ "$sockstat" = 'run' ] ; then + sv restart /etc/service/socklog-unix || echo "warning: failed to restart socklog-unix" + fi + fi +fi diff --git a/debian/socklog-run.postrm b/debian/socklog-run.postrm new file mode 100644 index 0000000..83fd340 --- /dev/null +++ b/debian/socklog-run.postrm @@ -0,0 +1,19 @@ +#!/bin/sh +set -e + +#remove/purge socklog-unix and socklog-klog when runit is not init, see #1112379 +if [ ! -f /etc/runit/stopit ] && [ -z "$DPKG_ROOT" ] ; then + #if [ "$1" = "remove" ]; then + # [ -d /etc/sv/socklog-unix ] && touch /etc/sv/socklog-unix/down + # [ -d /etc/sv/socklog-klog ] && touch /etc/sv/socklog-klog/down + #fi + if [ "$1" = "purge" ]; then + [ -h /etc/runit/runsvdir/svmanaged/.socklog-unix ] && unlink /etc/runit/runsvdir/svmanaged/.socklog-unix + [ -h /etc/runit/runsvdir/svmanaged/.socklog-klog ] && unlink /etc/runit/runsvdir/svmanaged/.socklog-klog + [ -f /etc/sv/socklog-unix/down ] && unlink /etc/sv/socklog-unix/down + [ -f /etc/sv/socklog-klog/down ] && unlink /etc/sv/socklog-klog/down + #other than this, debhelper 's purge should do fine + fi +fi + +#DEBHELPER# diff --git a/debian/socklog-run.prerm b/debian/socklog-run.prerm new file mode 100644 index 0000000..1dfd5fa --- /dev/null +++ b/debian/socklog-run.prerm @@ -0,0 +1,26 @@ +#!/bin/sh +set -e + +#DEBHELPER# + +#stop socklog-unix and socklog-klog when runit is not init, see #1112379 +if [ ! -f /etc/runit/stopit ] && [ "$1" = remove ] && [ -z "$DPKG_ROOT" ]; then + if [ -x /usr/sbin/policy-rc.d ]; then #policy-rc.d layer, likely the installer or a build chroot + set +e ; /usr/sbin/policy-rc.d ; rc=$? ; set -e + if [ "$rc" = "101" ]; then + echo "socklog-unix; socklog-klog: action denied by policy-rc.d" && exit 0 + fi + fi + #disable instead of stopping to avoid issues in postrm + if pidof runsvdir > /dev/null ; then + [ -d /etc/sv/socklog-unix ] && touch /etc/sv/socklog-unix/down + [ -d /etc/sv/socklog-klog ] && touch /etc/sv/socklog-klog/down + #sv d socklog-unix || true + #sv d socklog-klog || true + [ -h /etc/runit/runsvdir/svmanaged/socklog-unix ] && unlink /etc/runit/runsvdir/svmanaged/socklog-unix + [ -h /etc/runit/runsvdir/svmanaged/socklog-klog ] && unlink /etc/runit/runsvdir/svmanaged/socklog-klog + # force a rescan to reduce chances of a race in postrm + supervisor=$(pidof runsvdir) + kill -s ALRM "$supervisor" || echo "warning: force-rescan on runsvdir failed" + fi +fi -- 2.51.0

