tags 734848 +patch
thanks

Hi Michael,

On 23:25 Fri 10 Jan     , Michael Stapelberg wrote:
> Agreed. If you want to accelerate things, please attach a patch. Also,
> FYI, I won’t work on this until #727708 is resolved.

Please find attached a patch implementing the suggested behaviour 
(inspired mostly by /usr/sbin/service).

Regards,
Apollon

From 0bb95761cd8a71b9b6abc07f64ed6c34017d60cc Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos <apoi...@debian.org>
Date: Wed, 5 Feb 2014 19:20:00 +0200
Subject: [PATCH] LSB: start/stop service-triggering sockets

The LSB initscript wrapper functions handle starting/stopping individual
services, however they do not handle the corresponding sockets. The most
important effect of this is that "/etc/init.d/foo stop" will stop foo
only temporarily if foo is socket-activated, since the next connection
to the socket will cause systemd to re-activate the service.

We solve this issue by also stopping/starting any sockets triggering the
given service.

Closes: #734848
---
 debian/init-functions.d/40-systemd | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/debian/init-functions.d/40-systemd b/debian/init-functions.d/40-systemd
index a213afc..e494ac2 100644
--- a/debian/init-functions.d/40-systemd
+++ b/debian/init-functions.d/40-systemd
@@ -40,6 +40,7 @@ systemctl_redirect () {
     local rc
     local prog=${1##*/}
     local command=$2
+    local sockets=""
 
     case "$command" in
         start)
@@ -64,7 +65,27 @@ systemctl_redirect () {
     state=$(systemctl -p LoadState show $service 2>/dev/null)
     [ "$state" = "LoadState=masked" ] && return 0
 
-    [ "$command" = status ] || log_daemon_msg "$s" "$service"
+    # We also start/stop the associated sockets (if any), so that
+    # "/etc/init.d/foo stop" permanently stops the service.
+    if [ "$command" = start -o "$command" = stop ]; then
+        for socket in $(systemctl list-unit-files --full --type=socket \
+                                  --no-legend 2>/dev/null \
+                        | sed -ne 's/\.socket\s*[a-z]*\s*$/.socket/p'); do
+
+            # Only handle successfully loaded sockets triggering this service
+            triggers=$(systemctl -p Triggers show "$socket" 2>/dev/null)
+            state=$(systemctl -p LoadState show "$service" 2>/dev/null)
+
+            if [ "$state" = "LoadState=loaded" -a \
+                 "$triggers" = "Triggers=$service" ]; then
+                sockets="$socket $sockets"
+                /bin/systemctl $command "$socket"
+            fi
+        done
+    fi
+
+    [ "$command" = status ] || log_daemon_msg "$s" "${sockets}${service}"
+
     /bin/systemctl $command "$service"
     rc=$?
     [ "$command" = status ] || log_end_msg $rc
-- 
2.0.0.rc0

Attachment: signature.asc
Description: Digital signature

Reply via email to