From d37458ad063b04439455fa7c54c3d2abf25a1f5a Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 30 Sep 2016 17:05:31 +0300 Subject: switch-to-configuration: fix restart of socket activated services This fixes two bugs: * When socket activation is detected, the service itself is added to stop-start list instead of its sockets. * When service is marked to restart instead of stop (`StopIfChanged = no`) we don't need to restart sockets. --- .../system/activation/switch-to-configuration.pl | 40 ++++++++++------------ 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'nixos/modules/system/activation') diff --git a/nixos/modules/system/activation/switch-to-configuration.pl b/nixos/modules/system/activation/switch-to-configuration.pl index bb97d0c53a6b..8747c1e3d4ac 100644 --- a/nixos/modules/system/activation/switch-to-configuration.pl +++ b/nixos/modules/system/activation/switch-to-configuration.pl @@ -213,33 +213,30 @@ while (my ($unit, $state) = each %{$activePrev}) { elsif (!boolIsTrue($unitInfo->{'X-RestartIfChanged'} // "yes") || boolIsTrue($unitInfo->{'RefuseManualStop'} // "no") ) { $unitsToSkip{$unit} = 1; } else { - # If this unit is socket-activated, then stop the - # socket unit(s) as well, and restart the - # socket(s) instead of the service. - my $socketActivated = 0; - if ($unit =~ /\.service$/) { - my @sockets = split / /, ($unitInfo->{Sockets} // ""); - if (scalar @sockets == 0) { - @sockets = ("$baseName.socket"); - } - foreach my $socket (@sockets) { - if (defined $activePrev->{$socket}) { - $unitsToStop{$unit} = 1; - $unitsToStart{$unit} = 1; - recordUnit($startListFile, $socket); - $socketActivated = 1; - } - } - } - if (!boolIsTrue($unitInfo->{'X-StopIfChanged'} // "yes")) { - # This unit should be restarted instead of # stopped and started. $unitsToRestart{$unit} = 1; recordUnit($restartListFile, $unit); - } else { + # If this unit is socket-activated, then stop the + # socket unit(s) as well, and restart the + # socket(s) instead of the service. + my $socketActivated = 0; + if ($unit =~ /\.service$/) { + my @sockets = split / /, ($unitInfo->{Sockets} // ""); + if (scalar @sockets == 0) { + @sockets = ("$baseName.socket"); + } + foreach my $socket (@sockets) { + if (defined $activePrev->{$socket}) { + $unitsToStop{$socket} = 1; + $unitsToStart{$socket} = 1; + recordUnit($startListFile, $socket); + $socketActivated = 1; + } + } + } # If the unit is not socket-activated, record # that this unit needs to be started below. @@ -251,7 +248,6 @@ while (my ($unit, $state) = each %{$activePrev}) { } $unitsToStop{$unit} = 1; - } } } -- cgit 1.4.1