Merge pull request #148751 from NixOS/feat/slight-stc-improvements

nixos/switch-to-configuration: Add small improvements

authored by Bernardo Meurer and committed by GitHub ebb7f07e be1c35e2

+21 -9
+14 -9
nixos/modules/system/activation/switch-to-configuration.pl
··· 11 12 my $out = "@out@"; 13 14 - # FIXME: maybe we should use /proc/1/exe to get the current systemd. 15 my $curSystemd = abs_path("/run/current-system/sw/bin"); 16 17 # To be robust against interruption, record what units need to be started etc. ··· 25 my $dryRestartByActivationFile = "/run/nixos/dry-activation-restart-list"; 26 my $dryReloadByActivationFile = "/run/nixos/dry-activation-reload-list"; 27 28 - make_path("/run/nixos", { mode => 0755 }); 29 30 my $action = shift @ARGV; 31 ··· 219 } 220 221 elsif (fingerprintUnit($prevUnitFile) ne fingerprintUnit($newUnitFile)) { 222 - if ($unit eq "sysinit.target" || $unit eq "basic.target" || $unit eq "multi-user.target" || $unit eq "graphical.target") { 223 # Do nothing. These cannot be restarted directly. 224 } elsif ($unit =~ /\.mount$/) { 225 # Reload the changed mount unit to force a remount. 226 $unitsToReload{$unit} = 1; 227 recordUnit($reloadListFile, $unit); 228 - } elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/ || $unit =~ /\.slice$/) { 229 # FIXME: do something? 230 } else { 231 my $unitInfo = parseUnit($newUnitFile); ··· 382 split('\n', read_file($dryReloadByActivationFile, err_mode => 'quiet') // ""); 383 384 print STDERR "would restart systemd\n" if $restartSystemd; 385 print STDERR "would restart the following units: ", join(", ", sort(keys %unitsToRestart)), "\n" 386 if scalar(keys %unitsToRestart) > 0; 387 print STDERR "would start the following units: ", join(", ", @unitsToStartFiltered), "\n" 388 if scalar @unitsToStartFiltered; 389 - print STDERR "would reload the following units: ", join(", ", sort(keys %unitsToReload)), "\n" 390 - if scalar(keys %unitsToReload) > 0; 391 unlink($dryRestartByActivationFile); 392 unlink($dryReloadByActivationFile); 393 exit 0; ··· 400 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" 401 if scalar @unitsToStopFiltered; 402 # Use current version of systemctl binary before daemon is reexeced. 403 - system("$curSystemd/systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors? 404 } 405 406 print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n" ··· 485 486 487 # Print failed and new units. 488 - my (@failed, @new, @restarting); 489 my $activeNew = getActiveUnits; 490 while (my ($unit, $state) = each %{$activeNew}) { 491 if ($state->{state} eq "failed") { ··· 501 push @failed, $unit; 502 } 503 } 504 - elsif ($state->{state} ne "failed" && !defined $activePrev->{$unit}) { 505 push @new, $unit; 506 } 507 }
··· 11 12 my $out = "@out@"; 13 14 my $curSystemd = abs_path("/run/current-system/sw/bin"); 15 16 # To be robust against interruption, record what units need to be started etc. ··· 24 my $dryRestartByActivationFile = "/run/nixos/dry-activation-restart-list"; 25 my $dryReloadByActivationFile = "/run/nixos/dry-activation-reload-list"; 26 27 + make_path("/run/nixos", { mode => oct(755) }); 28 29 my $action = shift @ARGV; 30 ··· 218 } 219 220 elsif (fingerprintUnit($prevUnitFile) ne fingerprintUnit($newUnitFile)) { 221 + if ($unit eq "sysinit.target" || $unit eq "basic.target" || $unit eq "multi-user.target" || $unit eq "graphical.target" || $unit =~ /\.path$/ || $unit =~ /\.slice$/) { 222 # Do nothing. These cannot be restarted directly. 223 + 224 + # Slices and Paths don't have to be restarted since 225 + # properties (resource limits and inotify watches) 226 + # seem to get applied on daemon-reload. 227 } elsif ($unit =~ /\.mount$/) { 228 # Reload the changed mount unit to force a remount. 229 $unitsToReload{$unit} = 1; 230 recordUnit($reloadListFile, $unit); 231 + } elsif ($unit =~ /\.socket$/) { 232 # FIXME: do something? 233 } else { 234 my $unitInfo = parseUnit($newUnitFile); ··· 385 split('\n', read_file($dryReloadByActivationFile, err_mode => 'quiet') // ""); 386 387 print STDERR "would restart systemd\n" if $restartSystemd; 388 + print STDERR "would reload the following units: ", join(", ", sort(keys %unitsToReload)), "\n" 389 + if scalar(keys %unitsToReload) > 0; 390 print STDERR "would restart the following units: ", join(", ", sort(keys %unitsToRestart)), "\n" 391 if scalar(keys %unitsToRestart) > 0; 392 print STDERR "would start the following units: ", join(", ", @unitsToStartFiltered), "\n" 393 if scalar @unitsToStartFiltered; 394 unlink($dryRestartByActivationFile); 395 unlink($dryReloadByActivationFile); 396 exit 0; ··· 403 print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n" 404 if scalar @unitsToStopFiltered; 405 # Use current version of systemctl binary before daemon is reexeced. 406 + system("$curSystemd/systemctl", "stop", "--", sort(keys %unitsToStop)); 407 } 408 409 print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n" ··· 488 489 490 # Print failed and new units. 491 + my (@failed, @new); 492 my $activeNew = getActiveUnits; 493 while (my ($unit, $state) = each %{$activeNew}) { 494 if ($state->{state} eq "failed") { ··· 504 push @failed, $unit; 505 } 506 } 507 + # Ignore scopes since they are not managed by this script but rather 508 + # created and managed by third-party services via the systemd dbus API. 509 + elsif ($state->{state} ne "failed" && !defined $activePrev->{$unit} && $unit !~ /\.scope$/) { 510 push @new, $unit; 511 } 512 }
+7
nixos/modules/system/activation/top-level.nix
··· 78 export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" 79 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 80 chmod +x $out/bin/switch-to-configuration 81 82 echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies 83
··· 78 export localeArchive="${config.i18n.glibcLocales}/lib/locale/locale-archive" 79 substituteAll ${./switch-to-configuration.pl} $out/bin/switch-to-configuration 80 chmod +x $out/bin/switch-to-configuration 81 + ${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) '' 82 + if ! output=$($perl/bin/perl -c $out/bin/switch-to-configuration 2>&1); then 83 + echo "switch-to-configuration syntax is not valid:" 84 + echo "$output" 85 + exit 1 86 + fi 87 + ''} 88 89 echo -n "${toString config.system.extraDependencies}" > $out/extra-dependencies 90