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.
This commit is contained in:
Tony An
2025-02-27 08:47:17 -06:00
parent b74d8b79e1
commit 6ba0768366

View File

@@ -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)