Revert systemd interface version to 2
The new systemd in 19.09 gives an "Access Denied" error when doing "systemctl daemon-reexec" on an 19.03 system. The fix is to use the previous systemctl to signal the daemon to re-exec itself. This ensures that users don't have to reboot when upgrading from NixOS 19.03 to 19.09.
This commit is contained in:
parent
b9ed9c7fed
commit
b20a0e49c8
|
@ -10,6 +10,9 @@ use Cwd 'abs_path';
|
||||||
|
|
||||||
my $out = "@out@";
|
my $out = "@out@";
|
||||||
|
|
||||||
|
# FIXME: maybe we should use /proc/1/exe to get the current systemd.
|
||||||
|
my $curSystemd = abs_path("/run/current-system/sw/bin");
|
||||||
|
|
||||||
# To be robust against interruption, record what units need to be started etc.
|
# To be robust against interruption, record what units need to be started etc.
|
||||||
my $startListFile = "/run/systemd/start-list";
|
my $startListFile = "/run/systemd/start-list";
|
||||||
my $restartListFile = "/run/systemd/restart-list";
|
my $restartListFile = "/run/systemd/restart-list";
|
||||||
|
@ -267,7 +270,7 @@ while (my ($unit, $state) = each %{$activePrev}) {
|
||||||
sub pathToUnitName {
|
sub pathToUnitName {
|
||||||
my ($path) = @_;
|
my ($path) = @_;
|
||||||
# Use current version of systemctl binary before daemon is reexeced.
|
# Use current version of systemctl binary before daemon is reexeced.
|
||||||
open my $cmd, "-|", "/run/current-system/sw/bin/systemd-escape", "--suffix=mount", "-p", $path
|
open my $cmd, "-|", "$curSystemd/systemd-escape", "--suffix=mount", "-p", $path
|
||||||
or die "Unable to escape $path!\n";
|
or die "Unable to escape $path!\n";
|
||||||
my $escaped = join "", <$cmd>;
|
my $escaped = join "", <$cmd>;
|
||||||
chomp $escaped;
|
chomp $escaped;
|
||||||
|
@ -370,7 +373,7 @@ if (scalar (keys %unitsToStop) > 0) {
|
||||||
print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n"
|
print STDERR "stopping the following units: ", join(", ", @unitsToStopFiltered), "\n"
|
||||||
if scalar @unitsToStopFiltered;
|
if scalar @unitsToStopFiltered;
|
||||||
# Use current version of systemctl binary before daemon is reexeced.
|
# Use current version of systemctl binary before daemon is reexeced.
|
||||||
system("/run/current-system/sw/bin/systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors?
|
system("$curSystemd/systemctl", "stop", "--", sort(keys %unitsToStop)); # FIXME: ignore errors?
|
||||||
}
|
}
|
||||||
|
|
||||||
print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n"
|
print STDERR "NOT restarting the following changed units: ", join(", ", sort(keys %unitsToSkip)), "\n"
|
||||||
|
@ -382,10 +385,12 @@ my $res = 0;
|
||||||
print STDERR "activating the configuration...\n";
|
print STDERR "activating the configuration...\n";
|
||||||
system("$out/activate", "$out") == 0 or $res = 2;
|
system("$out/activate", "$out") == 0 or $res = 2;
|
||||||
|
|
||||||
# Restart systemd if necessary.
|
# Restart systemd if necessary. Note that this is done using the
|
||||||
|
# current version of systemd, just in case the new one has trouble
|
||||||
|
# communicating with the running pid 1.
|
||||||
if ($restartSystemd) {
|
if ($restartSystemd) {
|
||||||
print STDERR "restarting systemd...\n";
|
print STDERR "restarting systemd...\n";
|
||||||
system("@systemd@/bin/systemctl", "daemon-reexec") == 0 or $res = 2;
|
system("$curSystemd/systemctl", "daemon-reexec") == 0 or $res = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Forget about previously failed services.
|
# Forget about previously failed services.
|
||||||
|
@ -401,8 +406,10 @@ while (my $f = <$listActiveUsers>) {
|
||||||
my ($uid, $name) = ($+{uid}, $+{user});
|
my ($uid, $name) = ($+{uid}, $+{user});
|
||||||
print STDERR "reloading user units for $name...\n";
|
print STDERR "reloading user units for $name...\n";
|
||||||
|
|
||||||
system("@su@", "-s", "@shell@", "-l", $name, "-c", "XDG_RUNTIME_DIR=/run/user/$uid @systemd@/bin/systemctl --user daemon-reload");
|
system("@su@", "-s", "@shell@", "-l", $name, "-c",
|
||||||
system("@su@", "-s", "@shell@", "-l", $name, "-c", "XDG_RUNTIME_DIR=/run/user/$uid @systemd@/bin/systemctl --user start nixos-activation.service");
|
"export XDG_RUNTIME_DIR=/run/user/$uid; " .
|
||||||
|
"$curSystemd/systemctl --user daemon-reexec; " .
|
||||||
|
"@systemd@/bin/systemctl --user start nixos-activation.service");
|
||||||
}
|
}
|
||||||
|
|
||||||
close $listActiveUsers;
|
close $listActiveUsers;
|
||||||
|
|
|
@ -223,7 +223,7 @@ in stdenv.mkDerivation {
|
||||||
# in a backwards-incompatible way. If the interface version of two
|
# in a backwards-incompatible way. If the interface version of two
|
||||||
# systemd builds is the same, then we can switch between them at
|
# systemd builds is the same, then we can switch between them at
|
||||||
# runtime; otherwise we can't and we need to reboot.
|
# runtime; otherwise we can't and we need to reboot.
|
||||||
passthru.interfaceVersion = 3;
|
passthru.interfaceVersion = 2;
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
homepage = http://www.freedesktop.org/wiki/Software/systemd;
|
homepage = http://www.freedesktop.org/wiki/Software/systemd;
|
||||||
|
|
Loading…
Reference in New Issue