diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-03-09 16:45:01 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-03-09 16:51:06 +0100 |
commit | 475df1a3508925fad24564eb86386f8dee469405 (patch) | |
tree | 6101250311add242bf75bcd3b033690eb1f29dad /nixos/modules/system | |
parent | a574065a81b2173ef319fd9d1830241285def1d4 (diff) | |
download | nixpkgs-475df1a3508925fad24564eb86386f8dee469405.tar nixpkgs-475df1a3508925fad24564eb86386f8dee469405.tar.gz nixpkgs-475df1a3508925fad24564eb86386f8dee469405.tar.bz2 nixpkgs-475df1a3508925fad24564eb86386f8dee469405.tar.lz nixpkgs-475df1a3508925fad24564eb86386f8dee469405.tar.xz nixpkgs-475df1a3508925fad24564eb86386f8dee469405.tar.zst nixpkgs-475df1a3508925fad24564eb86386f8dee469405.zip |
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.
Diffstat (limited to 'nixos/modules/system')
-rw-r--r-- | nixos/modules/system/activation/switch-to-configuration.pl | 30 |
1 files 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 45fb752aaaa..ce36bac2bdc 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 @@ while (my ($unit, $state) = each %{$activePrev}) { 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 @@ foreach my $device (keys %$prevSwaps) { 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 @@ if ($action eq "dry-activate") { 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 @@ if (scalar(keys %unitsToRestart) > 0) { # 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); |