feat(thothctl): add safe Pi core restart
This commit is contained in:
@@ -119,28 +119,9 @@ func updateWithHooks(ctx context.Context, runner Runner, request Request, hooks
|
||||
}
|
||||
}()
|
||||
|
||||
running, err := activeSessions(ctx, runner)
|
||||
if err != nil {
|
||||
if err := waitForInactiveSessions(ctx, runner, request.Drain, hooks.sleep); err != nil {
|
||||
return Result{StatePath: request.StatePath}, err
|
||||
}
|
||||
if running {
|
||||
if !request.Drain {
|
||||
return Result{StatePath: request.StatePath}, ErrActiveSessions
|
||||
}
|
||||
for attempts := 0; attempts < 30; attempts++ {
|
||||
running, err = activeSessions(ctx, runner)
|
||||
if err != nil {
|
||||
return Result{StatePath: request.StatePath}, err
|
||||
}
|
||||
if !running {
|
||||
break
|
||||
}
|
||||
hooks.sleep(time.Second)
|
||||
}
|
||||
if running {
|
||||
return Result{StatePath: request.StatePath}, ErrActiveSessions
|
||||
}
|
||||
}
|
||||
if err := Doctor(ctx, runner); err != nil {
|
||||
return Result{StatePath: request.StatePath}, err
|
||||
}
|
||||
@@ -192,7 +173,7 @@ func updateWithHooks(ctx context.Context, runner Runner, request Request, hooks
|
||||
result, retErr, clearMaintenance = failPreparation(request.StatePath, overridePath, state, err, hooks)
|
||||
return result, retErr
|
||||
}
|
||||
running, err = activeSessions(ctx, runner)
|
||||
running, err := activeSessions(ctx, runner)
|
||||
if err != nil {
|
||||
result, retErr, clearMaintenance = failPreparation(request.StatePath, overridePath, state, err, hooks)
|
||||
return result, retErr
|
||||
@@ -554,6 +535,30 @@ func activeSessions(ctx context.Context, runner Runner) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func waitForInactiveSessions(ctx context.Context, runner Runner, drain bool, sleep func(time.Duration)) error {
|
||||
running, err := activeSessions(ctx, runner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !running {
|
||||
return nil
|
||||
}
|
||||
if !drain {
|
||||
return ErrActiveSessions
|
||||
}
|
||||
for attempts := 0; attempts < 30; attempts++ {
|
||||
running, err = activeSessions(ctx, runner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !running {
|
||||
return nil
|
||||
}
|
||||
sleep(time.Second)
|
||||
}
|
||||
return ErrActiveSessions
|
||||
}
|
||||
|
||||
func runningImage(ctx context.Context, runner Runner, reference string) (Image, error) {
|
||||
container, err := runCompose(ctx, runner, "ps", "-q", "core")
|
||||
if err != nil || strings.TrimSpace(container.Stdout) == "" {
|
||||
@@ -808,6 +813,10 @@ func RecoverMaintenance(ctx context.Context, runner Runner, statePath string, co
|
||||
return err
|
||||
}
|
||||
defer lock.Release()
|
||||
return recoverMaintenanceLocked(ctx, runner, statePath)
|
||||
}
|
||||
|
||||
func recoverMaintenanceLocked(ctx context.Context, runner Runner, statePath string) error {
|
||||
state, stateErr := readState(statePath)
|
||||
if stateErr == nil {
|
||||
transactionOverride := lifecycleOverridePath(statePath, state.Transaction)
|
||||
|
||||
Reference in New Issue
Block a user