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

auto-update: stop+start instead of restart sytemd units #17959

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force, remo

// Remove the container's CID file on container removal.
if cidFile, ok := c.config.Spec.Annotations[define.InspectAnnotationCIDFile]; ok {
if err := os.Remove(cidFile); err != nil {
if err := os.Remove(cidFile); err != nil && !errors.Is(err, os.ErrNotExist) {
if cleanupErr == nil {
cleanupErr = err
} else {
Expand Down
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