[PATCH] Add support for systemd >= 214 to update-rc.d [v2]

Jon Severinsson jon at severinsson.net
Sat Jul 12 20:09:22 BST 2014


Changes v2:
    Call systemctl reload-daemon *after* running insserv, not before.
---
 debian/changelog                    |  6 ++++++
 debian/src/sysv-rc/sbin/update-rc.d | 29 +++++++++++++++--------------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index f3ab9e72..de54364d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+sysvinit (2.88dsf-55.3) experimental; urgency=medium
+
+  * Add support for systemd >= 214 to update-rc.d
+
+ -- Jon Severinsson <jon at severinsson.net>  Fri, 04 Jun 2014 22:00:00 +0200
+
 sysvinit (2.88dsf-55.2) experimental; urgency=medium
 
   * Fix a formatting error in mountnfs which turned a tab character into
diff --git a/debian/src/sysv-rc/sbin/update-rc.d b/debian/src/sysv-rc/sbin/update-rc.d
index fdd1485b..816d5acd 100755
--- a/debian/src/sysv-rc/sbin/update-rc.d
+++ b/debian/src/sysv-rc/sbin/update-rc.d
@@ -68,41 +68,35 @@ sub make_path {
 sub make_systemd_links {
     my ($scriptname, $action) = @_;
 
+    my $unit = "$scriptname";
+    $unit =~ s/(\.sh)?$/.service/;
+
     # 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 (-f "/etc/systemd/system/$unit") {
+        $service_path = "/etc/systemd/system/$unit";
+    } elsif (-f "/lib/systemd/system/$unit") {
+        $service_path = "/lib/systemd/system/$unit";
     }
     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";
+                my $service_link = "$wants_dir/$unit";
                 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 && -d "/run/systemd/system") {
-            system("systemctl", "daemon-reload");
-        }
     }
 }
 
@@ -224,6 +218,13 @@ sub insserv_updatercd {
             save_last_action($scriptname, @orig_argv);
         }
         error_code($rc, "insserv rejected the script header") if $rc;
+
+        # If this machine is running systemd, tell systemd to reload
+        # so that it will pick up our changes.
+        if (!$notreally && -d "/run/systemd/system") {
+            system("systemctl", "daemon-reload");
+        }
+
         exit $rc;
     } else {
         usage();
-- 
2.0.0





More information about the Pkg-systemd-maintainers mailing list