Bug#768456: Version 3 including ansgar's and pitti's feedback

Didier Roche didrocks at ubuntu.com
Wed Nov 12 10:50:22 GMT 2014


Le 10/11/2014 07:04, Martin Pitt a écrit :

Hey Martin,
>> The downside is that we loose the return code, indeed (we could
>> concatenate it if needed).
> Yes, I think it should save the return code if it's != 0 and return
> that. I. e. the script will fail if processing any unit fails.

done, deb-systemd-invoke now returns latest unit error code it may found 
(and print which one(s) in STDERR).

I added as well, as ansgar's suggested that we don't start static units 
(not being able to find as well any good reason we would want to 
autostart them).

Please find attached v4 of the debdiff with those 2 changes.
Cheers,
Didier
-------------- next part --------------
diff -Nru init-system-helpers-1.21/debian/changelog init-system-helpers-1.22/debian/changelog
--- init-system-helpers-1.21/debian/changelog	2014-08-21 07:40:58.000000000 +0200
+++ init-system-helpers-1.22/debian/changelog	2014-11-12 11:44:36.000000000 +0100
@@ -1,3 +1,18 @@
+init-system-helpers (1.22) UNRELEASED; urgency=medium
+
+  * deb-system-invoke: don't start disabled systemd services (in case
+    of systemd only services), when there is no init script. (Closes: #768456)
+    Add some conditions to start the job on deb-system-invoke [restart|start],
+    during package upgrade:
+    - deb-system-invoke start <unit> don't do anything on systemd if the
+      unit is disabled or static.
+    - deb-system-invoke restart <unit> only restart a disabled or static unit
+      if the daemon was already running (forced by the admin).
+    - in case of multiple units in error passed to deb-system-invoke, this one
+      will exit with last unit in errror exit code.
+
+ -- Didier Roche <didrocks at ubuntu.com>  Fri, 07 Nov 2014 15:01:27 +0100
+
 init-system-helpers (1.21) unstable; urgency=medium
 
   * Demote augeas-tools to Suggests and let the systemd2init tool error out
diff -Nru init-system-helpers-1.21/script/deb-systemd-invoke init-system-helpers-1.22/script/deb-systemd-invoke
--- init-system-helpers-1.21/script/deb-systemd-invoke	2014-08-21 07:40:58.000000000 +0200
+++ init-system-helpers-1.22/script/deb-systemd-invoke	2014-11-12 11:42:44.000000000 +0100
@@ -77,4 +77,36 @@
     }
 }
 
-exec '/bin/systemctl', @ARGV;
+# If the job is disabled and is not currently running, the job is not started or restarted.
+# However, if the job is disabled but has been forced into the running state, we *do* stop
+# and restart it since this is expected behaviour for the admin who forced the start.
+# We don't autostart static units either.
+if ($action eq "start" || $action eq "restart") {
+    my $global_exit_code = 0;
+    for my $unit (@units) {
+        my $unit_installed = 0;
+        my $enabled_output = `/bin/systemctl is-enabled -- $unit`;
+        # matching enabled and enabled-runtime as an installed non static unit
+        if ($enabled_output =~ /enabled/) {
+            $unit_installed = 1;
+        }
+        system('/bin/systemctl', '--quiet', 'is-active', '--', $unit);
+        my $unit_active = $?>>8 == 0 ? 1 : 0;
+        if (!$unit_installed && $action eq "start") {
+            print STDERR "$unit is a disabled or a static unit, not starting it.\n";
+        } elsif (!$unit_installed && !$unit_active && $action eq "restart") {
+            print STDERR "$unit is a disabled or a static unit not running, not starting it.\n";
+        }
+        else {
+            system('/bin/systemctl', "$action", "$unit");
+            my $exit_code = $?>>8;
+            if ($exit_code != 0) {
+                print STDERR "$unit couldn't $action.\n";
+                $global_exit_code = $exit_code;
+            }
+        }
+    }
+    exit($global_exit_code);
+} else {
+    exec '/bin/systemctl', @ARGV;
+}


More information about the Pkg-systemd-maintainers mailing list