Here is the v3 of the patch, which includes ansgar's and pitti's
feedback. Thanks to them!
The only suggestion I couldn't integrate is Martin's system vs exec one.
I had to change keep it as system() call as we are evaluating one unit
after another as the scripts can accepts multiple units, and so exec
would prefer the evaluation and inclusion of other units passed as
parameters.
Does this make sense? The downside is that we loose the return code,
indeed (we could concatenate it if needed).
Cheers,
Didier
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-07 15:13:08.000000000
+0100
@@ -1,3 +1,16 @@
+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.
+ Add some conditions to start the job on deb-system-invoke [restart|start],
+ during package upgrade: (Closes: #768456)
+ - deb-system-invoke start <unit> don't do anything on systemd if the
+ service is disabled.
+ - deb-system-invoke restart <unit> only restart a disabled service if
+ if the daemon was already running (forced by the admin).
+
+ -- Didier Roche <[email protected]> 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-07
17:08:10.000000000 +0100
@@ -77,4 +77,24 @@
}
}
-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.
+if ($action eq "start" || $action eq "restart") {
+ for my $unit (@units) {
+ system('/bin/systemctl', '--quiet', 'is-enabled', '--', $unit);
+ my $unit_enabled = $?>>8 == 0 ? 1 : 0;
+ system('/bin/systemctl', '--quiet', 'is-active', '--', $unit);
+ my $unit_active = $?>>8 == 0 ? 1 : 0;
+ if (!$unit_enabled && $action eq "start") {
+ print STDERR "$unit is disabled, not starting it.\n";
+ } elsif (!$unit_enabled && !$unit_active && $action eq "restart") {
+ print STDERR "$unit is disabled and not running, not starting
it.\n";
+ }
+ else {
+ system('/bin/systemctl', "$action", "$unit");
+ }
+ }
+} else {
+ exec '/bin/systemctl', @ARGV;
+}