switch-to-configuration: Respect the ‘restartIfChanged’ attribute
This commit is contained in:
parent
7d958dcdd1
commit
a44e575196
@ -383,7 +383,7 @@ in
|
|||||||
{ wantedBy = [ "graphical.target" ];
|
{ wantedBy = [ "graphical.target" ];
|
||||||
after = [ "systemd-udev-settle.service" ];
|
after = [ "systemd-udev-settle.service" ];
|
||||||
|
|
||||||
#restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
|
|
||||||
environment =
|
environment =
|
||||||
{ FONTCONFIG_FILE = "/etc/fonts/fonts.conf"; # !!! cleanup
|
{ FONTCONFIG_FILE = "/etc/fonts/fonts.conf"; # !!! cleanup
|
||||||
|
@ -75,12 +75,23 @@ sub parseFstab {
|
|||||||
return %res;
|
return %res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub parseUnit {
|
||||||
|
my ($filename) = @_;
|
||||||
|
my $info = {};
|
||||||
|
foreach my $line (read_file($filename)) {
|
||||||
|
# FIXME: not quite correct.
|
||||||
|
$line =~ /^([^=]+)=(.*)$/ or next;
|
||||||
|
$info->{$1} = $2;
|
||||||
|
}
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
# Forget about previously failed services.
|
# Forget about previously failed services.
|
||||||
system("@systemd@/bin/systemctl", "reset-failed");
|
system("@systemd@/bin/systemctl", "reset-failed");
|
||||||
|
|
||||||
# Stop all services that no longer exist or have changed in the new
|
# Stop all services that no longer exist or have changed in the new
|
||||||
# configuration.
|
# configuration.
|
||||||
my @unitsToStop;
|
my (@unitsToStop, @unitsToSkip);
|
||||||
my $activePrev = getActiveUnits;
|
my $activePrev = getActiveUnits;
|
||||||
while (my ($unit, $state) = each %{$activePrev}) {
|
while (my ($unit, $state) = each %{$activePrev}) {
|
||||||
my $baseUnit = $unit;
|
my $baseUnit = $unit;
|
||||||
@ -102,11 +113,16 @@ while (my ($unit, $state) = each %{$activePrev}) {
|
|||||||
} elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/) {
|
} elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/) {
|
||||||
# FIXME: do something?
|
# FIXME: do something?
|
||||||
} else {
|
} else {
|
||||||
# Record that this unit needs to be started below. We
|
my $unitInfo = parseUnit($newUnitFile);
|
||||||
# write this to a file to ensure that the service gets
|
if ($unitInfo->{'X-RestartIfChanged'} eq "false") {
|
||||||
# restarted if we're interrupted.
|
push @unitsToSkip, $unit;
|
||||||
write_file($restartListFile, { append => 1 }, "$unit\n");
|
} else {
|
||||||
push @unitsToStop, $unit;
|
# Record that this unit needs to be started below. We
|
||||||
|
# write this to a file to ensure that the service gets
|
||||||
|
# restarted if we're interrupted.
|
||||||
|
write_file($restartListFile, { append => 1 }, "$unit\n");
|
||||||
|
push @unitsToStop, $unit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,6 +175,9 @@ if (scalar @unitsToStop > 0) {
|
|||||||
system("@systemd@/bin/systemctl", "stop", "--", @unitsToStop); # FIXME: ignore errors?
|
system("@systemd@/bin/systemctl", "stop", "--", @unitsToStop); # FIXME: ignore errors?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print STDERR "NOT restarting the following units: ", join(", ", sort(@unitsToSkip)), "\n"
|
||||||
|
if scalar @unitsToSkip > 0;
|
||||||
|
|
||||||
# Activate the new configuration (i.e., update /etc, make accounts,
|
# Activate the new configuration (i.e., update /etc, make accounts,
|
||||||
# and so on).
|
# and so on).
|
||||||
my $res = 0;
|
my $res = 0;
|
||||||
|
@ -115,6 +115,15 @@ with pkgs.lib;
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
restartIfChanged = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = ''
|
||||||
|
Whether the service should be restarted during a NixOS
|
||||||
|
configuration switch if its definition has changed.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -199,6 +199,7 @@ let
|
|||||||
[Service]
|
[Service]
|
||||||
Environment=PATH=${def.path}
|
Environment=PATH=${def.path}
|
||||||
${concatMapStrings (n: "Environment=${n}=${getAttr n def.environment}\n") (attrNames def.environment)}
|
${concatMapStrings (n: "Environment=${n}=${getAttr n def.environment}\n") (attrNames def.environment)}
|
||||||
|
${optionalString (!def.restartIfChanged) "X-RestartIfChanged=false"}
|
||||||
|
|
||||||
${optionalString (def.preStart != "") ''
|
${optionalString (def.preStart != "") ''
|
||||||
ExecStartPre=${makeJobScript "${name}-prestart.sh" ''
|
ExecStartPre=${makeJobScript "${name}-prestart.sh" ''
|
||||||
|
@ -54,7 +54,7 @@ let
|
|||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
|
|
||||||
inherit (job) description requires wants before partOf environment path;
|
inherit (job) description requires wants before partOf environment path restartIfChanged;
|
||||||
|
|
||||||
after =
|
after =
|
||||||
(if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else
|
(if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else
|
||||||
@ -185,15 +185,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
restartIfChanged = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = true;
|
|
||||||
description = ''
|
|
||||||
Whether the job should be restarted if it has changed after a
|
|
||||||
NixOS configuration switch.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
task = mkOption {
|
task = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
@ -302,8 +293,6 @@ in
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
system.build.upstart = "/no-upstart";
|
|
||||||
|
|
||||||
boot.systemd.services =
|
boot.systemd.services =
|
||||||
flip mapAttrs' config.jobs (name: job:
|
flip mapAttrs' config.jobs (name: job:
|
||||||
nameValuePair "${job.name}.service" job.unit);
|
nameValuePair "${job.name}.service" job.unit);
|
||||||
|
Loading…
Reference in New Issue
Block a user