-
-
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/home-assistant: reload the daemon when configuration changed #151241
Conversation
configFile | ||
lovelaceConfigFile | ||
]; | ||
reloadIfChanged = true; |
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.
Mhm, this should probably depend on !configWritable && !lovelaceConfigWritable
?
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.
Additionally, you should add a note somewhere reminding users of the security implications here - "Please restart this service whenever a security update is released" or some such.
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.
Actually that is already happening and I'm testing that in the VM test. As soon as the binary changes the service restarts anyway.
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.
Until #49528 is properly fixed there is actually a workaround we are using downstream. It's ugly but works and it doesn't add security implications.
Just add a second service that reloads the main service and give the reload service the restart triggers. Then don't give the main service restartIfChanged=true
I have included parts of our exim module as an example:
exim module
{
systemd.services.exim-reload = {
description = "Exim config reload";
wantedBy = [ "multi-user.target" ];
stopIfChanged = false;
restartTriggers = [ config.environment.etc."exim.conf".source ];
script = ''
# Ensure the unit is already active
${config.systemd.package}/bin/systemctl is-active exim.service >/dev/null || exit 0
${config.systemd.package}/bin/systemctl reload-or-restart exim.service
'';
sandbox = 2;
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
User = "exim";
Group = "exim";
SystemCallFilter = "@system-service";
};
apparmor = {
enable = true;
extraConfig = ''
/run/dbus/system_bus_socket rw,
'';
};
};
security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units" &&
action.lookup("unit") == "exim.service" &&
action.lookup("verb") == "reload-or-restart" &&
subject.user == "exim") {
return polkit.Result.YES;
}
});
'';
}
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.
@dasJ can you explain why this works as expected then? Did you have a look at the test code that I added to this PR?
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.
I looked at the code now. I have really no idea why that works. Are you 100% sure it gets reloaded once and restarted the second time and it's not hass restarting itself? Printing the switch-to-configuration.pl call should explain what it's asking systemd to do
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.
Unfortunately the reloadIfChanged feature isn't really documented well (or correct). My current working theory is that the restartIfChanged
list is an additional list of restart triggers and the reloadIfChanged
boolean switches to reloading instead of restarting when the list changes. Meaning that it actually does exactly what we want in this case. The naming of these options is very unfortunate but I think it is working as expected.
I'll see if I can get this deployed tonight and give it some real-world testing as well was writing a VM test for the restartIfChanged semantics.
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.
ping @flokli because of past conversations about how we thought if ExecStart
ever changes the service should be restarted... we were both under the impression reloadIfChanged
forces the service to never restart. Brief conversations with @mweinelt leave me with the impression that they also think this... 🤔
Thanks for offering to look into this @andir! And thanks for your feedback @dasJ!
Just found this PR and I really have to wonder how I missed it or forgot looking into it. Having a proper reload mechanism would be awesome to have. I think I'll annoy Janne, who has been working on this topic quite recently. |
Oh no |
Reload the service when configuration changes. This means that we don't have a potentially slow startup for every small configuration change.
7a6322c
to
cfbcf38
Compare
Rebased and did a few cosmetical changes. The use of specializations for the test scenario is neat. Thanks for providing these. @ofborg test home-assistant |
With multiple specialization changes this isn't very helpful anymore, but no biggie since we check the log for errors anyway and the log is not too verbose anyway.
1ca0704
to
d26a6e3
Compare
Motivation for this change
Reload the service when configuration changes. This means that we don't
have a potentially slow startup for every small configuration change.
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