diff options
Diffstat (limited to 'cmd/deploy/restart.go')
| -rw-r--r-- | cmd/deploy/restart.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/cmd/deploy/restart.go b/cmd/deploy/restart.go new file mode 100644 index 0000000..d1cfa86 --- /dev/null +++ b/cmd/deploy/restart.go | |||
| @@ -0,0 +1,57 @@ | |||
| 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 restartCmd = &cobra.Command{ | ||
| 12 | Use: "restart <app>", | ||
| 13 | Short: "Restart a deployment", | ||
| 14 | Args: cobra.ExactArgs(1), | ||
| 15 | RunE: runRestart, | ||
| 16 | } | ||
| 17 | |||
| 18 | func runRestart(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("restart 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 | fmt.Printf("Restarting %s...\n", name) | ||
| 51 | if _, err := client.RunSudo(fmt.Sprintf("systemctl restart %s", name)); err != nil { | ||
| 52 | return fmt.Errorf("error restarting service: %w", err) | ||
| 53 | } | ||
| 54 | |||
| 55 | fmt.Println("Service restarted successfully") | ||
| 56 | return nil | ||
| 57 | } | ||
