Hello! I'm attaching a completely untested attempt at prefering "systemctl preset" over just enabling unconditionally.
I've checked and it seems on a system running sysvinit-core and systemd package installed (eg. systemctl available) "systemctl preset ..." seems to do the right thing (as well as is-enabled, enable, disable, ...). This together with the fallback on the old enable when systemctl is not available should hopefully mean no regression in any case of init system package installation combos. Even if the patch actually works, there's definitely still some remaining work to be done here. See the comments in the patch itself. Comments welcome. Any other cases to consider that the ones who are already handled or mentioned in the patch? Anyone willing to test this and report back? Regards, Andreas Henriksson
From: Andreas Henriksson <andr...@fatal.se> Subject: Untested hacky attempt at prefering systemctl presets over enable. https://bugs.debian.org/772555 diff --git a/script/deb-systemd-helper b/script/deb-systemd-helper index 2a87cb4..af4f7d4 100755 --- a/script/deb-systemd-helper +++ b/script/deb-systemd-helper @@ -218,11 +218,55 @@ sub get_link_closure { return @links; } +sub is_enabled { + my ($scriptname, $service_path) = @_; + + my @links = get_link_closure($scriptname, $service_path); + my @missing_links = grep { ! -l $_->{src} } @links; + + return (@missing_links == 0); +} + sub make_systemd_links { my ($scriptname, $service_path) = @_; my $dsh_state = dsh_state_path($scriptname); + my $has_preset = 0; + + # prefer using systemctl preset, but if that's not available + # we use our own built-in hardcoded-to-enable fallback. + if (-x "/bin/systemctl") { + $has_preset = 1; + # Note: two consecutive is_enabled() will not properly + # tell us if something changed. We should compare the + # result from two get_link_closure() instead. + #my $prev_enabled = is_enabled($scriptname, $service_path); + my @prev_links = get_link_closure($scriptname, $service_path); + system("/bin/systemctl", "--preset-mode=enable-only", + "preset", $scriptname) or + error("systemctl preset failed on $scriptname: $!"); + #my $now_enabled = is_enabled($scriptname, $service_path); + my @links = get_link_closure($scriptname, $service_path); + #$changed_sth = ($prev_enabled != $now_enabled); + # N.B. Trying a "Smart Matching operator" posing like I actually + # know perl or if this even does the right thing. + $changed_sth = !(@prev_links ~~ @links); + # FIXME: We should really update statefile here when we still + # know something about the changed links instead of badly + # piggy-backing on the fallback which has no idea. + return unless $changed_sth; + } + # This fallback has dual purpose, if we used preset above + # it is still used to record links to dsh statefile. + # + # Note: this does not properly track state when using preset. + # (Consider the case where administrator has manually enabled + # bar.service. You're now installing foo(.service) which contains + # an Also=bar.service, which never got touched since it was already + # enabled before running the preset. It'll now be tracked as if + # we just enabled bar and will be disabled when uninstalling foo. + # OTOH, was this case even properly handled before?!) my @links = get_link_closure($scriptname, $service_path); for my $link (@links) { my $service_path = $link->{dest}; @@ -234,7 +278,7 @@ sub make_systemd_links { $statefile =~ s,^/etc/systemd/system/,$enabled_state_dir/,; next if -e $statefile; - if (! -l $service_link) { + if (!$has_preset && ! -l $service_link) { make_path(dirname($service_link)); symlink($service_path, $service_link) or error("unable to link $service_link to $service_path: $!"); @@ -472,9 +516,7 @@ for my $scriptname (@ARGV) { debug "action = $action, scriptname = $scriptname, service_path = $service_path"; if ($action eq 'is-enabled') { - my @links = get_link_closure($scriptname, $service_path); - my @missing_links = grep { ! -l $_->{src} } @links; - my $enabled = (@missing_links == 0); + my $enabled = is_enabled($scriptname, $service_path); print STDERR ($enabled ? "enabled\n" : "disabled\n") unless $quiet; $rc = 0 if $enabled; }
_______________________________________________ Pkg-systemd-maintainers mailing list Pkg-systemd-maintainers@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-systemd-maintainers