diff options
| author | bndw <ben@bdw.to> | 2026-01-24 09:48:34 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-01-24 09:48:34 -0800 |
| commit | 5861e465a2ccf31d87ea25ac145770786f9cc96e (patch) | |
| tree | 4ac6b57a06b46d8492717b235909f9e0db0b4f22 /cmd/deploy/logs.go | |
| parent | ef37850c7090493cf2b26d2e565511fe23cc9bfc (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/deploy/logs.go')
| -rw-r--r-- | cmd/deploy/logs.go | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/cmd/deploy/logs.go b/cmd/deploy/logs.go deleted file mode 100644 index 2b016b8..0000000 --- a/cmd/deploy/logs.go +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 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 logsCmd = &cobra.Command{ | ||
| 12 | Use: "logs <app>", | ||
| 13 | Short: "View logs for a deployment", | ||
| 14 | Args: cobra.ExactArgs(1), | ||
| 15 | RunE: runLogs, | ||
| 16 | } | ||
| 17 | |||
| 18 | func init() { | ||
| 19 | logsCmd.Flags().BoolP("follow", "f", false, "Follow logs") | ||
| 20 | logsCmd.Flags().IntP("lines", "n", 50, "Number of lines to show") | ||
| 21 | } | ||
| 22 | |||
| 23 | func runLogs(cmd *cobra.Command, args []string) error { | ||
| 24 | name := args[0] | ||
| 25 | follow, _ := cmd.Flags().GetBool("follow") | ||
| 26 | lines, _ := cmd.Flags().GetInt("lines") | ||
| 27 | |||
| 28 | st, err := state.Load() | ||
| 29 | if err != nil { | ||
| 30 | return fmt.Errorf("error loading state: %w", err) | ||
| 31 | } | ||
| 32 | |||
| 33 | host := hostFlag | ||
| 34 | if host == "" { | ||
| 35 | host = st.GetDefaultHost() | ||
| 36 | } | ||
| 37 | |||
| 38 | if host == "" { | ||
| 39 | return fmt.Errorf("--host is required") | ||
| 40 | } | ||
| 41 | |||
| 42 | app, err := st.GetApp(host, name) | ||
| 43 | if err != nil { | ||
| 44 | return err | ||
| 45 | } | ||
| 46 | |||
| 47 | if app.Type != "app" { | ||
| 48 | return fmt.Errorf("logs are only available for apps, not static sites") | ||
| 49 | } | ||
| 50 | |||
| 51 | client, err := ssh.Connect(host) | ||
| 52 | if err != nil { | ||
| 53 | return fmt.Errorf("error connecting to VPS: %w", err) | ||
| 54 | } | ||
| 55 | defer client.Close() | ||
| 56 | |||
| 57 | journalCmd := fmt.Sprintf("journalctl -u %s -n %d", name, lines) | ||
| 58 | if follow { | ||
| 59 | journalCmd += " -f" | ||
| 60 | } | ||
| 61 | |||
| 62 | if follow { | ||
| 63 | if err := client.RunStream(journalCmd); err != nil { | ||
| 64 | return fmt.Errorf("error fetching logs: %w", err) | ||
| 65 | } | ||
| 66 | } else { | ||
| 67 | output, err := client.Run(journalCmd) | ||
| 68 | if err != nil { | ||
| 69 | return fmt.Errorf("error fetching logs: %w", err) | ||
| 70 | } | ||
| 71 | fmt.Print(output) | ||
| 72 | } | ||
| 73 | |||
| 74 | return nil | ||
| 75 | } | ||
