switch-to-configuration: Respect the ‘restartIfChanged’ attribute
This commit is contained in:
parent
7d958dcdd1
commit
a44e575196
@ -383,7 +383,7 @@ in
|
||||
{ wantedBy = [ "graphical.target" ];
|
||||
after = [ "systemd-udev-settle.service" ];
|
||||
|
||||
#restartIfChanged = false;
|
||||
restartIfChanged = false;
|
||||
|
||||
environment =
|
||||
{ FONTCONFIG_FILE = "/etc/fonts/fonts.conf"; # !!! cleanup
|
||||
|
@ -75,12 +75,23 @@ sub parseFstab {
|
||||
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.
|
||||
system("@systemd@/bin/systemctl", "reset-failed");
|
||||
|
||||
# Stop all services that no longer exist or have changed in the new
|
||||
# configuration.
|
||||
my @unitsToStop;
|
||||
my (@unitsToStop, @unitsToSkip);
|
||||
my $activePrev = getActiveUnits;
|
||||
while (my ($unit, $state) = each %{$activePrev}) {
|
||||
my $baseUnit = $unit;
|
||||
@ -101,6 +112,10 @@ while (my ($unit, $state) = each %{$activePrev}) {
|
||||
write_file($reloadListFile, { append => 1 }, "$unit\n");
|
||||
} elsif ($unit =~ /\.socket$/ || $unit =~ /\.path$/) {
|
||||
# FIXME: do something?
|
||||
} else {
|
||||
my $unitInfo = parseUnit($newUnitFile);
|
||||
if ($unitInfo->{'X-RestartIfChanged'} eq "false") {
|
||||
push @unitsToSkip, $unit;
|
||||
} else {
|
||||
# Record that this unit needs to be started below. We
|
||||
# write this to a file to ensure that the service gets
|
||||
@ -110,6 +125,7 @@ while (my ($unit, $state) = each %{$activePrev}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub pathToUnitName {
|
||||
@ -159,6 +175,9 @@ if (scalar @unitsToStop > 0) {
|
||||
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,
|
||||
# and so on).
|
||||
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]
|
||||
Environment=PATH=${def.path}
|
||||
${concatMapStrings (n: "Environment=${n}=${getAttr n def.environment}\n") (attrNames def.environment)}
|
||||
${optionalString (!def.restartIfChanged) "X-RestartIfChanged=false"}
|
||||
|
||||
${optionalString (def.preStart != "") ''
|
||||
ExecStartPre=${makeJobScript "${name}-prestart.sh" ''
|
||||
|
@ -54,7 +54,7 @@ let
|
||||
'';
|
||||
in {
|
||||
|
||||
inherit (job) description requires wants before partOf environment path;
|
||||
inherit (job) description requires wants before partOf environment path restartIfChanged;
|
||||
|
||||
after =
|
||||
(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 {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
@ -302,8 +293,6 @@ in
|
||||
|
||||
config = {
|
||||
|
||||
system.build.upstart = "/no-upstart";
|
||||
|
||||
boot.systemd.services =
|
||||
flip mapAttrs' config.jobs (name: job:
|
||||
nameValuePair "${job.name}.service" job.unit);
|
||||
|
Loading…
Reference in New Issue
Block a user