From 475df1a3508925fad24564eb86386f8dee469405 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 9 Mar 2015 16:45:01 +0100 Subject: [PATCH] switch-to-configuration: Don't print already active target units Since we restart all active target units (of which there are many), it's hard to see the units that actually matter. So don't print that we're starting target units that are already active. --- .../activation/switch-to-configuration.pl | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index 45fb752aaaa62..ce36bac2bdcf8 100644 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -132,6 +132,8 @@ sub fingerprintUnit { # Figure out what units need to be stopped, started, restarted or reloaded. my (%unitsToStop, %unitsToSkip, %unitsToStart, %unitsToRestart, %unitsToReload); +my %unitsToFilter; # units not shown + $unitsToStart{$_} = 1 foreach split('\n', read_file($startListFile, err_mode => 'quiet') // ""); @@ -171,6 +173,8 @@ sub fingerprintUnit { unless (boolIsTrue($unitInfo->{'RefuseManualStart'} // "no")) { $unitsToStart{$unit} = 1; recordUnit($startListFile, $unit); + # Don't spam the user with target units that always get started. + $unitsToFilter{$unit} = 1; } } @@ -321,16 +325,30 @@ sub unique { my $restartSystemd = abs_path("/proc/1/exe") ne abs_path("@systemd@/lib/systemd/systemd"); +sub filterUnits { + my ($units) = @_; + my @res; + foreach my $unit (sort(keys %{$units})) { + push @res, $unit if !defined $unitsToFilter{$unit}; + } + return @res; +} + +my @unitsToStopFiltered = filterUnits(\%unitsToStop); +my @unitsToStartFiltered = filterUnits(\%unitsToStart); + + # Show dry-run actions. if ($action eq "dry-activate") { - print STDERR "would stop the following units: ", join(", ", sort(keys %unitsToStop)), "\n" - if scalar(keys %unitsToStop) > 0; + print STDERR "would stop the following units: ", join(", ", @unitsToStopFiltered), "\n" + if scalar @unitsToStopFiltered > 0; print STDERR "would NOT stop the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n" if scalar(keys %unitsToSkip) > 0; print STDERR "would restart systemd\n" if $restartSystemd; print STDERR "would restart the following units: ", join(", ", sort(keys %unitsToRestart)), "\n" if scalar(keys %unitsToRestart) > 0; - print STDERR "would start the following units: ", join(", ", sort(keys %unitsToStart)), "\n"; + print STDERR "would start the following units: ", join(", ", @unitsToStartFiltered), "\n" + if scalar @unitsToStartFiltered; print STDERR "would reload the following units: ", join(", ", sort(keys %unitsToReload)), "\n" if scalar(keys %unitsToReload) > 0; exit 0; @@ -340,7 +358,8 @@ sub unique { syslog(LOG_NOTICE, "switching to system configuration $out"); if (scalar (keys %unitsToStop) > 0) { - print STDERR "stopping the following units: ", join(", ", sort(keys %unitsToStop)), "\n"; + print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" + if scalar @unitsToStopFiltered; system("systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? } @@ -383,7 +402,8 @@ sub unique { # that are symlinks to other units. We shouldn't start both at the # same time because we'll get a "Failed to add path to set" error from # systemd. -print STDERR "starting the following units: ", join(", ", sort(keys %unitsToStart)), "\n"; +print STDERR "starting the following units: ", join(", ", @unitsToStartFiltered), "\n" + if scalar @unitsToStartFiltered; system("@systemd@/bin/systemctl", "start", "--", sort(keys %unitsToStart)) == 0 or $res = 4; unlink($startListFile);