-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/switch-to-configuration: Document and test handling of socket-activated services #161838
nixos/switch-to-configuration: Document and test handling of socket-activated services #161838
Conversation
@ofborg test switchTest |
Also cc @aanderse to remind people that you want the script rewritten ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a flaw 😢 This will break services where ExecStop
relies on still having the old etc
.
I'm not confident that this can be fixed without fixing systemd or mutating the old units. We really need to inhibit the old service start; otherwise it seems we'll have to introduce new corner cases.
nixos/tests/switch-test.nix
Outdated
out = switch_to_specialisation("${machine}", "simple-socket-stop-if-changed-and-execstop") | ||
assert_contains(out, "stopping the following units: socket-activated.service, socket-activated.socket\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This switches from a non-ExecStop service to an ExecStop one, so it doesn't need to stop the socket yet, but does need to do so on the next switch, even when ExecStop is removed.
default), the behavior depends on whether `ExecStop=` is set. If set, the | ||
`.socket` unit and the `.service` unit are **stop**ped and the `.socket` | ||
unit is **start**ed. This is required to prevent races. If `ExecStop=` is | ||
not set, there is no need to touch the `.socket` unit. Instead, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that despite stopIfChanged
being enabled, the old service will run until after etc
has been switched.
I don't think that's acceptable.
@roberth thank you for reviewing the change. Do you have an alternative suggestion I can implement? If we don't come to an agreement I can redo this PR to only clean the code, add test cases, and add docs to at least have the current behavior properly specified and tested. |
79349fe
to
df75fef
Compare
I removed most of the logic after a longer discussion with Robert. We came to the conclusion that there was no way we can keep up with the race-free nature of the current behavior (please correct me if I got your points wrong). So this PR mostly adds test cases and proper docs for handling of socket-activated units and leaves the current logic intact. |
@@ -339,21 +340,23 @@ sub handleModifiedUnit { | |||
# 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; | |||
my $socket_activated = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this snake case when all the other variables are camel case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, but what is unitsToReload
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is currently a mix between camel case (not yet refactored) and snake case (already refactored)
nixos/tests/switch-test.nix
Outdated
# Socket-activated services don't get started, just the socket | ||
machine.fail("[ -S /run/test.sock ]") | ||
out = switch_to_specialisation("${machine}", "simple-socket") | ||
# assert_lacks(out, "stopping the following units:") nobody cares |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not throw it out then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it clear that this check was left out explicitly and not just forgotten
assert_lacks(out, "reloading the following units:") | ||
assert_contains(out, "restarting the following units: test-timer.timer\n") | ||
assert_contains(out, "\nrestarting the following units: test-timer.timer\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why aren't we stripping away the spaces from each out
variable (or rather in the switch_to_specialisation
function)? is it important to check the newline everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because restarting the following units
and starting the following units
must somehow be differentiated and using regex would be pretty expensive to run hundreds of times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, i didn't know out
was a string, thought it was an array, my bad
df75fef
to
d56d805
Compare
If there are no more strong opinions, I'd merge this today or so. It's mostly docs and tests and doesn't touch the logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the suggestions from my comment just now. Lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
d56d805
to
f6ad15f
Compare
Motivation for this change
More tests, more docs
The manual should explain what this is doing exactly.
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes