From fce7915ec041da12d2a018781fec7e8e43bb7e42 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Sun, 22 Dec 2024 12:56:34 +0200 Subject: [PATCH] add zinit restart command --- pkg/zinit/commands.go | 12 ++++++++---- pkg/zos_api/admin.go | 6 +----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/zinit/commands.go b/pkg/zinit/commands.go index 6efd3847c..a057441ce 100644 --- a/pkg/zinit/commands.go +++ b/pkg/zinit/commands.go @@ -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" ) @@ -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 @@ -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) diff --git a/pkg/zos_api/admin.go b/pkg/zos_api/admin.go index 2474e6b0e..018b7a428 100644 --- a/pkg/zos_api/admin.go +++ b/pkg/zos_api/admin.go @@ -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) {