Hi Roger,

As discussed on IRC, here is another patch which makes the defaults and
remove action systemd-aware, too (so that many packages work better
without changing them at all).

Please have a look if everything’s alright with the patch.

Best regards,
Michael
From 5fd43c4f511d548780a510987b4a5674d7052685 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <stapelb...@debian.org>
Date: Sun, 29 Jul 2012 19:31:58 +0200
Subject: [PATCH] Enable/disable systemd service on 'defaults' and 'remove'

---
 debian/src/sysv-rc/sbin/update-rc.d |   85 ++++++++++++++++++++---------------
 1 file changed, 50 insertions(+), 35 deletions(-)

diff --git a/debian/src/sysv-rc/sbin/update-rc.d b/debian/src/sysv-rc/sbin/update-rc.d
index 6357c0f..fb5b009 100755
--- a/debian/src/sysv-rc/sbin/update-rc.d
+++ b/debian/src/sysv-rc/sbin/update-rc.d
@@ -356,6 +356,49 @@ sub makelinks {
     1;
 }
 
+# Creates the necessary links to enable/disable the service (equivalent of an
+# initscript) in systemd.
+sub make_systemd_links {
+    my ($scriptname, $action) = @_;
+
+    # In addition to the insserv call we also enable/disable the service
+    # for systemd by creating the appropriate symlink in case there is a
+    # native systemd service. We need to do this on our own instead of
+    # using systemctl because systemd might not even be installed yet.
+    my $service_path;
+    if (-f "/etc/systemd/system/$scriptname.service") {
+        $service_path = "/etc/systemd/system/$scriptname.service";
+    } elsif (-f "/lib/systemd/system/$scriptname.service") {
+        $service_path = "/lib/systemd/system/$scriptname.service";
+    }
+    if (defined($service_path)) {
+        my $changed_sth;
+        open my $fh, '<', $service_path or error("unable to read $service_path");
+        while (<$fh>) {
+            chomp;
+            if (/^\s*WantedBy=(.+)$/i) {
+                my $wants_dir = "/etc/systemd/system/$1.wants";
+                my $service_link = "$wants_dir/$scriptname.service";
+                if ("enable" eq $action) {
+                    make_path($wants_dir);
+                    symlink($service_path, $service_link);
+                } else {
+                    unlink($service_link) if -e $service_link;
+                }
+                $changed_sth = 1;
+            }
+        }
+        close($fh);
+
+        # If we changed anything and this machine is running systemd, tell
+        # systemd to reload so that it will immediately pick up our
+        # changes.
+        if ($changed_sth && -e "/sys/fs/cgroup/systemd") {
+            system("systemctl", "daemon-reload");
+        }
+    }
+}
+
 ## Dependency based
 sub insserv_updatercd {
     my @args = @_;
@@ -379,6 +422,8 @@ sub insserv_updatercd {
     $scriptname = shift @args;
     $action = shift @args;
     if ("remove" eq $action) {
+        make_systemd_links($scriptname, "disable");
+
         if ( -f "/etc/init.d/$scriptname" ) {
             my $rc = system("/sbin/insserv", @opts, "-r", $scriptname) >> 8;
             if (0 == $rc && !$notreally) {
@@ -398,6 +443,10 @@ sub insserv_updatercd {
         }
     } elsif ("defaults" eq $action || "start" eq $action ||
              "stop" eq $action) {
+        if ("defaults" eq $action) {
+            make_systemd_links($scriptname, "enable");
+        }
+
         # All start/stop/defaults arguments are discarded so emit a
         # message if arguments have been given and are in conflict
         # with Default-Start/Default-Stop values of LSB comment.
@@ -414,42 +463,8 @@ sub insserv_updatercd {
             error("initscript does not exist: /etc/init.d/$scriptname");
         }
     } elsif ("disable" eq $action || "enable" eq $action) {
-        # In addition to the insserv call we also enable/disable the service
-        # for systemd by creating the appropriate symlink in case there is a
-        # native systemd service. We need to do this on our own instead of
-        # using systemctl because systemd might not even be installed yet.
-        my $service_path;
-        if (-f "/etc/systemd/system/$scriptname.service") {
-            $service_path = "/etc/systemd/system/$scriptname.service";
-        } elsif (-f "/lib/systemd/system/$scriptname.service") {
-            $service_path = "/lib/systemd/system/$scriptname.service";
-        }
-        if (defined($service_path)) {
-            my $changed_sth;
-            open my $fh, '<', $service_path or error("unable to read $service_path");
-            while (<$fh>) {
-                chomp;
-                if (/^\s*WantedBy=(.+)$/i) {
-                    my $wants_dir = "/etc/systemd/system/$1.wants";
-                    my $service_link = "$wants_dir/$scriptname.service";
-                    if ("enable" eq $action) {
-                        make_path($wants_dir);
-                        symlink($service_path, $service_link);
-                    } else {
-                        unlink($service_link) if -e $service_link;
-                    }
-                    $changed_sth = 1;
-                }
-            }
-            close($fh);
+        make_systemd_links($scriptname, $action);
 
-            # If we changed anything and this machine is running systemd, tell
-            # systemd to reload so that it will immediately pick up our
-            # changes.
-            if ($changed_sth && -e "/sys/fs/cgroup/systemd") {
-                system("systemctl", "daemon-reload");
-            }
-        }
         insserv_toggle($notreally, $action, $scriptname, @args);
         # Call insserv to resequence modified links
         my $rc = system("insserv", @opts, $scriptname) >> 8;
-- 
1.7.10.4

Reply via email to