Skip to content

Commit

Permalink
auto-update: stop+start instead of restart sytemd units
Browse files Browse the repository at this point in the history
It turns out the restart is _not_ a stop+start but keeps certain
resources open and is subject to some timeouts that may differ across
distributions' default settings.

[NO NEW TESTS NEEDED] as I have absolutely no idea how to reliably cause
the failure/flake/race.

Fixes: containers#17607
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
  • Loading branch information
vrothberg authored and edsantiago committed Mar 29, 2023
1 parent 265fe61 commit aecd861
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions pkg/autoupdate/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,16 @@ func (t *task) rollbackImage() error {

// restartSystemdUnit restarts the systemd unit the container is running in.
func (u *updater) restartSystemdUnit(ctx context.Context, unit string) error {
if err := u.stopSystemdUnit(ctx, unit); err != nil {
return err
}
return u.startSystemdUnit(ctx, unit)
}

// startSystemdUnit starts the systemd unit the container is running in.
func (u *updater) startSystemdUnit(ctx context.Context, unit string) error {
restartChan := make(chan string)
if _, err := u.conn.RestartUnitContext(ctx, unit, "replace", restartChan); err != nil {
if _, err := u.conn.StartUnitContext(ctx, unit, "replace", restartChan); err != nil {
return err
}

Expand All @@ -349,7 +357,28 @@ func (u *updater) restartSystemdUnit(ctx context.Context, unit string) error {
return nil

default:
return fmt.Errorf("expected %q but received %q", "done", result)
return fmt.Errorf("error starting systemd unit %q expected %q but received %q", unit, "done", result)
}
}

// stopSystemdUnit stop the systemd unit the container is running in.
func (u *updater) stopSystemdUnit(ctx context.Context, unit string) error {
restartChan := make(chan string)
if _, err := u.conn.StopUnitContext(ctx, unit, "replace", restartChan); err != nil {
return err
}

// Wait for the restart to finish and actually check if it was
// successful or not.
result := <-restartChan

switch result {
case "done":
logrus.Infof("Successfully stopped systemd unit %q", unit)
return nil

default:
return fmt.Errorf("error stopping systemd unit %q expected %q but received %q", unit, "done", result)
}
}

Expand Down

0 comments on commit aecd861

Please sign in to comment.