Skip to content

Commit 46e4f4c

Browse files
lucarin91Xayton
andauthored
fix(update): always try to restart the app-cli daemon (#161)
* fix(update): always try to restart the app-cli daemon * Update internal/update/apt/service.go Co-authored-by: Alby <[email protected]> --------- Co-authored-by: Alby <[email protected]>
1 parent 64ba6dd commit 46e4f4c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

internal/update/apt/service.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
8383
defer s.lock.Unlock()
8484
defer close(eventsCh)
8585

86+
// At the end of the upgrade, always try to restart the services (that need it).
87+
// This makes sure key services are restarted even if an error happens in the upgrade steps (for examples container images download).
88+
defer func() {
89+
eventsCh <- update.NewDataEvent(update.RestartEvent, "Upgrade completed. Restarting ...")
90+
91+
err := restartServices(ctx)
92+
if err != nil {
93+
eventsCh <- update.NewErrorEvent(fmt.Errorf("error restarting services after upgrade: %w", err))
94+
return
95+
}
96+
}()
97+
8698
eventsCh <- update.NewDataEvent(update.StartEvent, "Upgrade is starting")
8799
stream := runUpgradeCommand(ctx, names)
88100
for line, err := range stream {
@@ -127,13 +139,6 @@ func (s *Service) UpgradePackages(ctx context.Context, names []string) (<-chan u
127139
}
128140
eventsCh <- update.NewDataEvent(update.UpgradeLineEvent, line)
129141
}
130-
eventsCh <- update.NewDataEvent(update.RestartEvent, "Upgrade completed. Restarting ...")
131-
132-
err := restartServices(ctx)
133-
if err != nil {
134-
eventsCh <- update.NewErrorEvent(fmt.Errorf("error restarting services after upgrade: %w", err))
135-
return
136-
}
137142
}()
138143

139144
return eventsCh, nil

0 commit comments

Comments
 (0)