Skip to content

Commit 6844a15

Browse files
committed
fix restart service
1 parent 4d9bf34 commit 6844a15

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

pkg/zinit/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (c *Client) Stop(service string) error {
337337
return c.cmd(fmt.Sprintf("stop %s", service), nil)
338338
}
339339

340-
// Re restarts a service.
340+
// Restart restarts a service.
341341
func (c *Client) Restart(service string) error {
342342
return c.cmd(fmt.Sprintf("restart %s", service), nil)
343343
}

pkg/zos_api/admin.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ import (
77
"os"
88
"path/filepath"
99

10+
"github.com/rs/zerolog/log"
1011
"github.com/threefoldtech/zos/pkg/zinit"
1112
)
1213

14+
func (g *ZosAPI) adminRebootHandler(ctx context.Context, payload []byte) (interface{}, error) {
15+
zinit := zinit.Default()
16+
17+
return nil, zinit.Reboot()
18+
}
19+
1320
func (g *ZosAPI) adminRestartServiceHandler(ctx context.Context, payload []byte) (interface{}, error) {
1421
var service string
1522
if err := json.Unmarshal(payload, &service); err != nil {
@@ -21,12 +28,6 @@ func (g *ZosAPI) adminRestartServiceHandler(ctx context.Context, payload []byte)
2128
return nil, zinit.Restart(service)
2229
}
2330

24-
func (g *ZosAPI) adminRebootHandler(ctx context.Context, payload []byte) (interface{}, error) {
25-
zinit := zinit.Default()
26-
27-
return nil, zinit.Reboot()
28-
}
29-
3031
func (g *ZosAPI) adminRestartAllHandler(ctx context.Context, payload []byte) (interface{}, error) {
3132
zinit := zinit.Default()
3233

@@ -35,9 +36,10 @@ func (g *ZosAPI) adminRestartAllHandler(ctx context.Context, payload []byte) (in
3536
return nil, fmt.Errorf("failed to list node services, expecting string: %w", err)
3637
}
3738

38-
for _, service := range services {
39-
if err := zinit.Restart(service.String()); err != nil {
40-
return nil, fmt.Errorf("failed to reboot service %s, expecting string: %w", service.String(), err)
39+
for service := range services {
40+
log.Debug().Str("service", service).Send()
41+
if err := zinit.Restart(service); err != nil {
42+
return nil, fmt.Errorf("failed to reboot service %s, expecting string: %w", service, err)
4143
}
4244
}
4345

0 commit comments

Comments
 (0)