-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (74 loc) · 2.05 KB
/
main.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"systemgo/internal"
"systemgo/internal/monitor"
"systemgo/internal/settings"
)
func getFilePath() string {
// Get the directory of the current working directory
ex, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to get current working directory: %v", err)
}
// Construct the default config file path
configPath := filepath.Join(ex, "internal", "settings", "settings.conf")
// Debug: Print the constructed path to ensure it's correct
// fmt.Println(configPath)
// log.Printf("Config file path: %s", configPath)
return configPath
}
func main() {
// Command-line flags
configFilePath := flag.String("config", getFilePath(), "Path to the config file")
monitorFlag := flag.String("monitor", "", "Enable live monitoring for a specific service")
flag.Parse()
// Initialize logging
internal.Init()
// Load config
config, err := settings.LoadConf(*configFilePath)
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
// Initialize services based on config
fmt.Println("Enabled services:")
services := internal.InitializeServices(config)
if len(services) == 0 {
log.Fatal("No services found")
}
// for name, svc := range services {
// fmt.Printf("Service: %s, Command: %s\n", name, svc.Command)
// }
if *monitorFlag != "" {
service, exists := services[*monitorFlag]
if !exists {
fmt.Printf("Service %s not found\n", *monitorFlag)
return
}
monitor.WatchService(service) // This should work correctly
return
}
// Handle command-line arguments
if len(flag.Args()) < 2 {
fmt.Println("Usage: <start/stop/restart/status> <service-name>")
return
}
action := flag.Arg(0)
serviceName := flag.Arg(1)
switch action {
case "start":
internal.StartService(serviceName, services)
case "stop":
internal.StopService(serviceName, services)
case "restart":
internal.RestartService(serviceName, services)
case "status":
internal.StatusService(serviceName, services)
default:
fmt.Println("usage: <application> <start/stop/restart/status> <service>")
}
}