From 06cbe6253788b4be2d5a3f2b3d36820cfc1b2b1b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 18 Oct 2012 13:26:47 -0400 Subject: [PATCH] switch-to-configuration: Support services activated by multiple sockets --- .../activation/switch-to-configuration.pl | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/system/activation/switch-to-configuration.pl b/modules/system/activation/switch-to-configuration.pl index 41487de9745..b085778f099 100644 --- a/modules/system/activation/switch-to-configuration.pl +++ b/modules/system/activation/switch-to-configuration.pl @@ -146,18 +146,29 @@ while (my ($unit, $state) = each %{$activePrev}) { { push @unitsToSkip, $unit; } else { - # If this unit has a corresponding socket unit, - # then stop the socket unit as well, and restart - # the socket instead of the service. - if ($unit =~ /\.service$/ && defined $activePrev->{"$baseName.socket"}) { - push @unitsToStop, "$baseName.socket"; - write_file($restartListFile, { append => 1 }, "$baseName.socket\n"); + # 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}) { + push @unitsToStop, $socket; + write_file($restartListFile, { append => 1 }, "$socket\n"); + $socketActivated = 1; + } + } } - # 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. - else { + # Otherwise, 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. + if (!$socketActivated) { write_file($restartListFile, { append => 1 }, "$unit\n"); }