summaryrefslogtreecommitdiffstats
path: root/cmd/ship/restart.go
diff options
context:
space:
mode:
authorbndw <ben@bdw.to>2026-01-24 09:48:34 -0800
committerbndw <ben@bdw.to>2026-01-24 09:48:34 -0800
commit5861e465a2ccf31d87ea25ac145770786f9cc96e (patch)
tree4ac6b57a06b46d8492717b235909f9e0db0b4f22 /cmd/ship/restart.go
parentef37850c7090493cf2b26d2e565511fe23cc9bfc (diff)
Rename project from deploy to ship
- Rename module to github.com/bdw/ship - Rename cmd/deploy to cmd/ship - Update all import paths - Update config path from ~/.config/deploy to ~/.config/ship - Update VPS env path from /etc/deploy to /etc/ship - Update README, Makefile, and docs
Diffstat (limited to 'cmd/ship/restart.go')
-rw-r--r--cmd/ship/restart.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmd/ship/restart.go b/cmd/ship/restart.go
new file mode 100644
index 0000000..2c74c62
--- /dev/null
+++ b/cmd/ship/restart.go
@@ -0,0 +1,57 @@
1package main
2
3import (
4 "fmt"
5
6 "github.com/bdw/ship/internal/ssh"
7 "github.com/bdw/ship/internal/state"
8 "github.com/spf13/cobra"
9)
10
11var restartCmd = &cobra.Command{
12 Use: "restart <app>",
13 Short: "Restart a deployment",
14 Args: cobra.ExactArgs(1),
15 RunE: runRestart,
16}
17
18func 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}