debugd: reset unit failed status before restarting (#3183)

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2024-06-20 11:22:37 +02:00 committed by GitHub
parent a36e1a79f0
commit c1e4da3ea1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View File

@ -91,6 +91,8 @@ type dbusConn interface {
// StopUnitContext is similar to StartUnitContext, but stops the specified unit
// rather than starting it.
StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
// ResetFailedUnitContext resets the "failed" state of a unit.
ResetFailedUnitContext(ctx context.Context, name string) error
// RestartUnitContext restarts a service. If a service is restarted that isn't
// running it will be started.
RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
@ -122,6 +124,9 @@ func (s *ServiceManager) SystemdAction(ctx context.Context, request ServiceManag
case Stop:
_, err = conn.StopUnitContext(ctx, request.Unit, "replace", resultChan)
case Restart:
if err = conn.ResetFailedUnitContext(ctx, request.Unit); err != nil {
s.log.Error("Failed to reset unit failed state", "error", err.Error(), "unit", request.Unit)
}
_, err = conn.RestartUnitContext(ctx, request.Unit, "replace", resultChan)
case Reload:
err = conn.ReloadContext(ctx)

View File

@ -356,6 +356,10 @@ func (c *fakeDbusConn) StopUnitContext(_ context.Context, name string, mode stri
return c.jobID, c.actionErr
}
func (c *fakeDbusConn) ResetFailedUnitContext(_ context.Context, _ string) error {
return nil
}
func (c *fakeDbusConn) RestartUnitContext(_ context.Context, name string, mode string, ch chan<- string) (int, error) {
c.inputs = append(c.inputs, dbusConnActionInput{name: name, mode: mode})
ch <- c.result

View File

@ -38,6 +38,10 @@ func (c *dbusConnWrapper) StopUnitContext(ctx context.Context, name string, mode
return c.conn.StopUnitContext(ctx, name, mode, ch)
}
func (c *dbusConnWrapper) ResetFailedUnitContext(ctx context.Context, name string) error {
return c.conn.ResetFailedUnitContext(ctx, name)
}
func (c *dbusConnWrapper) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
return c.conn.RestartUnitContext(ctx, name, mode, ch)
}