diff options
Diffstat (limited to 'cmd/ship/status.go')
| -rw-r--r-- | cmd/ship/status.go | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/cmd/ship/status.go b/cmd/ship/status.go deleted file mode 100644 index 4774fad..0000000 --- a/cmd/ship/status.go +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/bdw/ship/internal/ssh" | ||
| 7 | "github.com/bdw/ship/internal/state" | ||
| 8 | "github.com/spf13/cobra" | ||
| 9 | ) | ||
| 10 | |||
| 11 | var statusCmd = &cobra.Command{ | ||
| 12 | Use: "status <app>", | ||
| 13 | Short: "Check status of a deployment", | ||
| 14 | Args: cobra.ExactArgs(1), | ||
| 15 | RunE: runStatus, | ||
| 16 | } | ||
| 17 | |||
| 18 | func runStatus(cmd *cobra.Command, args []string) error { | ||
| 19 | name := args[0] | ||
| 20 | if err := validateName(name); err != nil { | ||
| 21 | return err | ||
| 22 | } | ||
| 23 | |||
| 24 | st, err := state.Load() | ||
| 25 | if err != nil { | ||
| 26 | return fmt.Errorf("error loading state: %w", err) | ||
| 27 | } | ||
| 28 | |||
| 29 | host := hostFlag | ||
| 30 | if host == "" { | ||
| 31 | host = st.GetDefaultHost() | ||
| 32 | } | ||
| 33 | |||
| 34 | if host == "" { | ||
| 35 | return fmt.Errorf("--host is required") | ||
| 36 | } | ||
| 37 | |||
| 38 | app, err := st.GetApp(host, name) | ||
| 39 | if err != nil { | ||
| 40 | return err | ||
| 41 | } | ||
| 42 | |||
| 43 | if app.Type != "app" && app.Type != "git-app" { | ||
| 44 | return fmt.Errorf("status is only available for apps, not static sites") | ||
| 45 | } | ||
| 46 | |||
| 47 | client, err := ssh.Connect(host) | ||
| 48 | if err != nil { | ||
| 49 | return fmt.Errorf("error connecting to VPS: %w", err) | ||
| 50 | } | ||
| 51 | defer client.Close() | ||
| 52 | |||
| 53 | output, err := client.RunSudo(fmt.Sprintf("systemctl status %s", name)) | ||
| 54 | if err != nil { | ||
| 55 | // systemctl status returns non-zero for non-active services | ||
| 56 | // but we still want to show the output | ||
| 57 | fmt.Print(output) | ||
| 58 | return nil | ||
| 59 | } | ||
| 60 | |||
| 61 | fmt.Print(output) | ||
| 62 | return nil | ||
| 63 | } | ||
