diff --git a/InfrastructureAgent/cmd/main.go b/InfrastructureAgent/cmd/main.go index b6a2003e49..1306da69b4 100644 --- a/InfrastructureAgent/cmd/main.go +++ b/InfrastructureAgent/cmd/main.go @@ -79,22 +79,15 @@ func main() { // Create the service s, err := service.New(prg, svcConfig) if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } - // Set up the logger - errs := make(chan error, 5) - l, err := s.Logger(errs) if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } - // Push the logger to the slog - logHandler := agentgo.NewServiceSysLogHandler(l) - slog.PushHandler(logHandler) - if len(os.Args) > 1 { cmd := os.Args[1] switch cmd { @@ -104,77 +97,77 @@ func main() { oneuptimeURL := installFlags.String("oneuptime-url", "", "Oneuptime endpoint root URL (required)") err := installFlags.Parse(os.Args[2:]) if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } prg.config.SecretKey = *secretKey prg.config.OneUptimeURL = *oneuptimeURL if prg.config.SecretKey == "" || prg.config.OneUptimeURL == "" { - slog.Fatal("The --secret-key and --oneuptime-url flags are required for the 'install' command") + slog.Error("The --secret-key and --oneuptime-url flags are required for the 'install' command") os.Exit(2) } // save configuration err = prg.config.save(prg.config.SecretKey, prg.config.OneUptimeURL) if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } // Install the service if err := s.Install(); err != nil { - slog.Fatal("Failed to install service: ", err) + slog.Error("Failed to install service: ", err) os.Exit(2) } fmt.Println("Service installed") case "start": err := prg.config.loadConfig() if os.IsNotExist(err) { - slog.Fatal("Service configuration not found. Please install the service properly.") + slog.Error("Service configuration not found. Please install the service properly.") os.Exit(2) } if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } if err != nil || prg.config.SecretKey == "" || prg.config.OneUptimeURL == "" { - slog.Fatal("Service configuration not found or is incomplete. Please install the service properly.") + slog.Error("Service configuration not found or is incomplete. Please install the service properly.") os.Exit(2) } err = s.Start() if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } slog.Info("Service Started") case "run": err := prg.config.loadConfig() if os.IsNotExist(err) { - slog.Fatal("Service configuration not found. Please install the service properly.") + slog.Error("Service configuration not found. Please install the service properly.") os.Exit(2) } if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } if err != nil || prg.config.SecretKey == "" || prg.config.OneUptimeURL == "" { - slog.Fatal("Service configuration not found or is incomplete. Please install the service properly.") + slog.Error("Service configuration not found or is incomplete. Please install the service properly.") os.Exit(2) } err = s.Run() if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } case "uninstall", "stop", "restart": err := service.Control(s, cmd) if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } if cmd == "uninstall" { // remove configuration file err := prg.config.removeConfigFile() if err != nil { - slog.Fatal(err) + slog.Error(err.Error()) os.Exit(2) } slog.Info("Service Uninstalled") diff --git a/InfrastructureAgent/agent.go b/InfrastructureAgent/utils/agent.go similarity index 100% rename from InfrastructureAgent/agent.go rename to InfrastructureAgent/utils/agent.go diff --git a/InfrastructureAgent/cpu.go b/InfrastructureAgent/utils/cpu.go similarity index 99% rename from InfrastructureAgent/cpu.go rename to InfrastructureAgent/utils/cpu.go index f8bec73b00..526b40e9d2 100644 --- a/InfrastructureAgent/cpu.go +++ b/InfrastructureAgent/utils/cpu.go @@ -3,8 +3,9 @@ package oneuptime_infrastructure_agent import ( "fmt" "log/slog" - "github.com/shirou/gopsutil/v3/cpu" "time" + + "github.com/shirou/gopsutil/v3/cpu" ) func getCpuMetrics() *CPUMetrics { diff --git a/InfrastructureAgent/disk.go b/InfrastructureAgent/utils/disk.go similarity index 100% rename from InfrastructureAgent/disk.go rename to InfrastructureAgent/utils/disk.go diff --git a/InfrastructureAgent/memory.go b/InfrastructureAgent/utils/memory.go similarity index 100% rename from InfrastructureAgent/memory.go rename to InfrastructureAgent/utils/memory.go diff --git a/InfrastructureAgent/procs.go b/InfrastructureAgent/utils/procs.go similarity index 100% rename from InfrastructureAgent/procs.go rename to InfrastructureAgent/utils/procs.go