Skip to content
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

wrappers,tests: restart always enabled units #12670

Merged
merged 2 commits into from
Apr 18, 2023

Conversation

alfonsosanchezbeato
Copy link
Member

Due to a previous change we were not restarting any non-running unit, but actually that should happen only if the unit is also disabled. Otherwise, stopping and the restarting will not work. Fixes LP#2012630. For reference, see [1], which looks like it might have been misinterpreted.

[1] https://forum.snapcraft.io/t/command-line-interface-to-manipulate-services/262/46

@mvo5 mvo5 added this to the 2.59 milestone Mar 30, 2023
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, as we discussed we should check if there is any intersection with the behavior around handling services during refreshes, I suspect not, but worth double checking

@alfonsosanchezbeato
Copy link
Member Author

thanks, as we discussed we should check if there is any intersection with the behavior around handling services during refreshes, I suspect not, but worth double checking

Refreshes do "stop-snap-services" and later a "start-snap-services". The former takes a list of the disabled services, not considering the running state. The latter restart the snap services but those in the list previously considered, so it looks like that behavior is already coherent with this PR.

RestartServices is called when doing a "snap restart" and when quota configuration is changed. For the latter, maybe the new behavior changes things (I do not know how automatic are these restarts) - cc @Meulengracht as maybe he can comment.

@Meulengracht
Copy link
Member

thanks, as we discussed we should check if there is any intersection with the behavior around handling services during refreshes, I suspect not, but worth double checking

Refreshes do "stop-snap-services" and later a "start-snap-services". The former takes a list of the disabled services, not considering the running state. The latter restart the snap services but those in the list previously considered, so it looks like that behavior is already coherent with this PR.

RestartServices is called when doing a "snap restart" and when quota configuration is changed. For the latter, maybe the new behavior changes things (I do not know how automatic are these restarts) - cc @Meulengracht as maybe he can comment.

I checked up on how we restart services in quota groups, and we do this when moving snaps in and out of service groups, were we restart services for that snap. It will of course change the behaviour, but I don't see this as an issue for the quota case.

@pedronis
Copy link
Collaborator

pedronis commented Apr 4, 2023

I checked up on how we restart services in quota groups, and we do this when moving snaps in and out of service groups, were we restart services for that snap. It will of course change the behaviour, but I don't see this as an issue for the quota case.

are we saying that now changing a quota group might restart services that were enabled but not running? it sounds like we might need different behavior for that vs snap(ctl) restart requests?

@alfonsosanchezbeato
Copy link
Member Author

I checked up on how we restart services in quota groups, and we do this when moving snaps in and out of service groups, were we restart services for that snap. It will of course change the behaviour, but I don't see this as an issue for the quota case.

are we saying that now changing a quota group might restart services that were enabled but not running? it sounds like we might need different behavior for that vs snap(ctl) restart requests?

Yes, to me it sounds like that too. Restarting when moving snaps across quota groups sounds like something transparent to the user that should respect the current state of the processes, which is different from requiring a restart from API.

@alfonsosanchezbeato
Copy link
Member Author

I've added now a flag to discriminate between restarting active services or not.

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question about the signature change vs consistency, otherwise this looks reasonable

@@ -1804,7 +1808,7 @@ type RestartServicesFlags struct {
// TODO: change explicitServices format to be less unusual, more consistent
// (introduce AppRef?)
func RestartServices(svcs []*snap.AppInfo, explicitServices []string,
flags *RestartServicesFlags, inter Interacter, tm timings.Measurer) error {
flags RestartServicesFlags, inter Interacter, tm timings.Measurer) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is a bit strange because now StopService and StartServices are inconsistent, I would leave things as they were

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted this part. In general I would prefer to force having to pass the parameter as it is more explicit and avoids checks for nil, but as things are the same for StopServices I guess that should be its own PR.

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@alfonsosanchezbeato
Copy link
Member Author

History rewritten with no code changes

@alfonsosanchezbeato
Copy link
Member Author

I've pushed now changes to fix the spread failures.

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questions

tests/main/services-restart/task.yaml Show resolved Hide resolved
// RestartOnlyActive is only for "restart" and "reload-or-restart"
// actions, and when set it restarts only the active services, that is,
// enabled non-running services are ignored.
RestartOnlyActive bool `json:"restart-only-active,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default of this is wrong for tasks that were made by old snapd though?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but I'm not sure on the concern here, tasks from older changes would have been already run by the old snapd, and anyway we are changing behavior, it does probably not matter if it affects a task created before snapd refreshes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

independent changes might be running while we update snapd, and it matters again if the tasks were about quota groups, I fear we need to make the default be the old behavior and deal with that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted the flag now

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more comments

tests/main/services-restart/task.yaml Show resolved Hide resolved
Action: "restart",
SnapName: info.InstanceName(),
Services: getServiceNames(servicesAffected[info]),
RestartEnabledNonActive: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we know we want false, but I suspect that there maybe other places where we want to set this to true? where do we also create ServiceAction tasks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot to change that, I've pushed changes to fix it.

@pedronis pedronis self-requested a review April 17, 2023 12:45
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

Due to a previous decision [1] we were not restarting any non-running
unit, this commit changes that back so non-running units are not
restarted only if the unit is also disabled. This way, stopping and
restarting works more similarly to how it is usually expected. Fixes
LP#2012630.

[1] https://forum.snapcraft.io/t/command-line-interface-to-manipulate-services/262/46
Now all enabled services are restarted.
@alfonsosanchezbeato
Copy link
Member Author

History rewritten and re-pushed now

@mvo5 mvo5 merged commit 130ddaa into snapcore:master Apr 18, 2023
47 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants