Skip to content

Commit 14b8c5c

Browse files
authored
feat(reboot): reboot after 10s by default (#670)
To inform the control plane that the reboot request has been processed, reboot after 10 seconds. Signed-off-by: Tao Li <[email protected]>
1 parent 1777e24 commit 14b8c5c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

pkg/host/reboot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func WithSystemctl(b bool) OpOption {
4545

4646
var ErrNotRoot = errors.New("must be run as sudo/root")
4747

48-
// Reboots the system.
48+
// Reboot reboots the system.
4949
func Reboot(ctx context.Context, opts ...OpOption) error {
5050
options := &Op{}
5151
if err := options.applyOpts(opts); err != nil {

pkg/session/serve.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,19 @@ func (s *Session) serve() {
7474
}
7575

7676
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
77-
if payload.Method == "reboot" {
78-
rerr := pkghost.Reboot(ctx, pkghost.WithDelaySeconds(0))
79-
80-
if rerr != nil {
81-
log.Logger.Errorf("failed to trigger reboot machine: %v", rerr)
82-
}
83-
84-
cancel()
85-
continue
86-
}
8777

8878
needExit := -1
8979
response := &Response{}
9080

9181
switch payload.Method {
82+
case "reboot":
83+
// To inform the control plane that the reboot request has been processed, reboot after 10 seconds.
84+
err := pkghost.Reboot(s.ctx, pkghost.WithDelaySeconds(10))
85+
if err != nil {
86+
log.Logger.Errorf("failed to trigger reboot machine: %v", err)
87+
response.Error = err.Error()
88+
}
89+
9290
case "metrics":
9391
metrics, err := s.getMetrics(ctx, payload)
9492
if err != nil {

0 commit comments

Comments
 (0)