diff options
Diffstat (limited to 'cmd/deploy/status.go')
| -rw-r--r-- | cmd/deploy/status.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/cmd/deploy/status.go b/cmd/deploy/status.go new file mode 100644 index 0000000..4bcfc68 --- /dev/null +++ b/cmd/deploy/status.go | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/bdw/deploy/internal/ssh" | ||
| 7 | "github.com/bdw/deploy/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 | |||
| 21 | st, err := state.Load() | ||
| 22 | if err != nil { | ||
| 23 | return fmt.Errorf("error loading state: %w", err) | ||
| 24 | } | ||
| 25 | |||
| 26 | host := hostFlag | ||
| 27 | if host == "" { | ||
| 28 | host = st.GetDefaultHost() | ||
| 29 | } | ||
| 30 | |||
| 31 | if host == "" { | ||
| 32 | return fmt.Errorf("--host is required") | ||
| 33 | } | ||
| 34 | |||
| 35 | app, err := st.GetApp(host, name) | ||
| 36 | if err != nil { | ||
| 37 | return err | ||
| 38 | } | ||
| 39 | |||
| 40 | if app.Type != "app" { | ||
| 41 | return fmt.Errorf("status is only available for apps, not static sites") | ||
| 42 | } | ||
| 43 | |||
| 44 | client, err := ssh.Connect(host) | ||
| 45 | if err != nil { | ||
| 46 | return fmt.Errorf("error connecting to VPS: %w", err) | ||
| 47 | } | ||
| 48 | defer client.Close() | ||
| 49 | |||
| 50 | output, err := client.RunSudo(fmt.Sprintf("systemctl status %s", name)) | ||
| 51 | if err != nil { | ||
| 52 | // systemctl status returns non-zero for non-active services | ||
| 53 | // but we still want to show the output | ||
| 54 | fmt.Print(output) | ||
| 55 | return nil | ||
| 56 | } | ||
| 57 | |||
| 58 | fmt.Print(output) | ||
| 59 | return nil | ||
| 60 | } | ||
