diff --git a/cmd/cli/commands_log.go b/cmd/cli/commands_log.go index 089a192..e2b9ff5 100644 --- a/cmd/cli/commands_log.go +++ b/cmd/cli/commands_log.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "net/http" "path/filepath" @@ -110,6 +111,15 @@ func (lc *LogCommand) ViewLogs(cmd *cobra.Command, args []string) error { case http.StatusMovedPermanently: lc.warnRuntimeLoggingNotEnabled() return nil + case http.StatusBadRequest: + mainLog.Load().Warn().Msg("runtime debugs log is not available") + buf, err := io.ReadAll(resp.Body) + if err != nil { + mainLog.Load().Fatal().Err(err).Msg("failed to read response body") + } + mainLog.Load().Warn().Msgf("ctrld process response:\n\n%s\n", string(buf)) + return nil + case http.StatusOK: } var logs logViewResponse @@ -117,11 +127,6 @@ func (lc *LogCommand) ViewLogs(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to decode view logs result: %w", err) } - if logs.Data == "" { - mainLog.Load().Notice().Msg("No runtime logs available") - return nil - } - fmt.Print(logs.Data) return nil } diff --git a/cmd/cli/commands_service_restart.go b/cmd/cli/commands_service_restart.go index dcad4c1..8764046 100644 --- a/cmd/cli/commands_service_restart.go +++ b/cmd/cli/commands_service_restart.go @@ -2,8 +2,10 @@ package cli import ( "context" + "errors" "time" + "github.com/kardianos/service" "github.com/spf13/cobra" ) @@ -19,6 +21,11 @@ func (sc *ServiceCommand) Restart(cmd *cobra.Command, args []string) error { return err } + if _, err := s.Status(); errors.Is(err, service.ErrNotInstalled) { + mainLog.Load().Warn().Msg("service not installed") + return nil + } + p.cfg = &cfg if iface == "" { iface = "auto"