-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathruntime_cli.go
More file actions
68 lines (60 loc) · 1.68 KB
/
Copy pathruntime_cli.go
File metadata and controls
68 lines (60 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package launchdock
import (
"fmt"
"os"
runtimepkg "github.com/nghiahoang/launchdock/internal/runtime"
)
func ensureServerRunning(cfg LaunchConfig) error { return runtimepkg.EnsureServerRunning(cfg.RawURL) }
func handlePSCommand() {
cfg := resolveRuntimeConfig()
status, pid := runtimepkg.DaemonStatus(cfg.RawURL)
fmt.Print("launchdock ps\n\n")
fmt.Printf("status: %s\n", status)
if pid > 0 {
fmt.Printf("pid: %d\n", pid)
}
fmt.Printf("url: %s\n", cfg.RawURL)
fmt.Printf("log: %s\n\n", runtimepkg.DaemonLogPath())
}
func handleStopCommand() {
if err := runtimepkg.StopServer(); err != nil {
fmt.Fprintf(os.Stderr, "✗ %v\n", err)
os.Exit(1)
}
fmt.Println("✓ launchdock stopped")
}
func handleRestartCommand() {
cfg := resolveRuntimeConfig()
_ = runtimepkg.StopServer()
if err := runtimepkg.EnsureServerRunning(cfg.RawURL); err != nil {
fmt.Fprintf(os.Stderr, "✗ %v\n", err)
os.Exit(1)
}
fmt.Printf("✓ launchdock restarted at %s\n", cfg.RawURL)
}
func handleStartCommand() {
cfg := resolveRuntimeConfig()
if err := runtimepkg.EnsureServerRunning(cfg.RawURL); err != nil {
fmt.Fprintf(os.Stderr, "✗ %v\n", err)
os.Exit(1)
}
status, pid := runtimepkg.DaemonStatus(cfg.RawURL)
if pid > 0 {
fmt.Printf("✓ launchdock %s at %s (pid %d)\n", status, cfg.RawURL, pid)
return
}
fmt.Printf("✓ launchdock %s at %s\n", status, cfg.RawURL)
}
func handleLogsCommand() {
path := runtimepkg.DaemonLogPath()
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "✗ no log file at %s\n", path)
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "✗ read log failed: %v\n", err)
os.Exit(1)
}
fmt.Print(string(data))
}