From 6ba0768366f77502747428ba3fb6058b143fddf5 Mon Sep 17 00:00:00 2001 From: Tony An Date: Thu, 27 Feb 2025 08:47:17 -0600 Subject: [PATCH] :sparkles: Add `status` command to check service state Introduced a new `status` command to display the service state (running, stopped, or unknown). Improved user feedback by logging the status and handling potential errors during the status check. --- InfrastructureAgent/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/InfrastructureAgent/main.go b/InfrastructureAgent/main.go index f76bd46471..1ee2a0f8c9 100644 --- a/InfrastructureAgent/main.go +++ b/InfrastructureAgent/main.go @@ -206,7 +206,19 @@ func main() { // add help command case "help": fmt.Println("Usage: oneuptime-infrastructure-agent configure | uninstall | start | stop | restart") - + case "status": + s, err := s.Status() + if err != nil { + slog.Error(err.Error()) + os.Exit(2) + } + if s == service.StatusRunning { + slog.Info("Service is running") + } else if s == service.StatusStopped { + slog.Info("Service is stopped") + } else { + slog.Info("Service status unknown") + } default: slog.Error("Invalid command") os.Exit(2)