Skip to content

Commit 4bb02f2

Browse files
committed
add zinit restart command
1 parent ada96ac commit 4bb02f2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg/zinit/commands.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const (
4545
ServiceStateSuccess = "success"
4646
// ServiceStateError is return when we a service exit with an error (exit code != 0)
4747
ServiceStateError = "error"
48-
//ServiceStateFailure is set of zinit can not spawn a service in the first place
49-
//due to a missing executable for example. Unlike `error` which is returned if the
50-
//service itself exits with an error.
48+
// ServiceStateFailure is set of zinit can not spawn a service in the first place
49+
// due to a missing executable for example. Unlike `error` which is returned if the
50+
// service itself exits with an error.
5151
ServiceStateFailure = "failure"
5252
)
5353

@@ -204,7 +204,6 @@ type ServiceStatus struct {
204204
func (c *Client) List() (out map[string]ServiceState, err error) {
205205
err = c.cmd("list", &out)
206206
return
207-
208207
}
209208

210209
// Status returns the status of a service
@@ -310,6 +309,11 @@ func (c *Client) Stop(service string) error {
310309
return c.cmd(fmt.Sprintf("stop %s", service), nil)
311310
}
312311

312+
// Re restarts a service.
313+
func (c *Client) Restart(service string) error {
314+
return c.cmd(fmt.Sprintf("restart %s", service), nil)
315+
}
316+
313317
// StartWait starts a service and wait until its running, or until the timeout
314318
// (seconds) pass. If timedout, the method returns an error if the service is not running
315319
// timout of 0 means no wait. (similar to Stop)

pkg/zos_api/admin.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ func (g *ZosAPI) adminRestartHandler(ctx context.Context, payload []byte) (inter
1616

1717
zinit := zinit.Default()
1818

19-
if err := zinit.Stop(service); err != nil {
20-
return nil, err
21-
}
22-
23-
return nil, zinit.Start(service)
19+
return nil, zinit.Restart(service)
2420
}
2521

2622
func (g *ZosAPI) adminRebootHandler(ctx context.Context, payload []byte) (interface{}, error) {

0 commit comments

Comments
 (0)