Skip to content

Commit

Permalink
add zinit restart command
Browse files Browse the repository at this point in the history
  • Loading branch information
Eslam-Nawara committed Dec 22, 2024
1 parent ada96ac commit 4bb02f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 8 additions & 4 deletions pkg/zinit/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ const (
ServiceStateSuccess = "success"
// ServiceStateError is return when we a service exit with an error (exit code != 0)
ServiceStateError = "error"
//ServiceStateFailure is set of zinit can not spawn a service in the first place
//due to a missing executable for example. Unlike `error` which is returned if the
//service itself exits with an error.
// ServiceStateFailure is set of zinit can not spawn a service in the first place
// due to a missing executable for example. Unlike `error` which is returned if the
// service itself exits with an error.
ServiceStateFailure = "failure"
)

Expand Down Expand Up @@ -204,7 +204,6 @@ type ServiceStatus struct {
func (c *Client) List() (out map[string]ServiceState, err error) {
err = c.cmd("list", &out)
return

}

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

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

// StartWait starts a service and wait until its running, or until the timeout
// (seconds) pass. If timedout, the method returns an error if the service is not running
// timout of 0 means no wait. (similar to Stop)
Expand Down
6 changes: 1 addition & 5 deletions pkg/zos_api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ func (g *ZosAPI) adminRestartHandler(ctx context.Context, payload []byte) (inter

zinit := zinit.Default()

if err := zinit.Stop(service); err != nil {
return nil, err
}

return nil, zinit.Start(service)
return nil, zinit.Restart(service)
}

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

0 comments on commit 4bb02f2

Please sign in to comment.