Skip to content

Commit

Permalink
switch-to-configuration: Don't print already active target units
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edolstra committed Mar 9, 2015
1 parent a574065 commit 475df1a
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions nixos/modules/system/activation/switch-to-configuration.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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') // "");

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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?
}

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 475df1a

Please sign in to comment.