From 0a90736338c8c397e1f8006174f71a9beb9c99df Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 14 May 2024 12:23:15 +0100 Subject: [PATCH] chore: Configure OneUptime Infrastructure Agent as a system service ``` --- InfrastructureAgent/README.md | 6 ++++-- InfrastructureAgent/install.sh | 2 +- InfrastructureAgent/main.go | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/InfrastructureAgent/README.md b/InfrastructureAgent/README.md index b8b17fb609..21dbedc0d0 100644 --- a/InfrastructureAgent/README.md +++ b/InfrastructureAgent/README.md @@ -14,11 +14,13 @@ Run the Installation Script chmod +x install.sh && ./install.sh ``` -Install the agent as a system service +## Configure the agent + +Configure the agent as a system service - You can change the host to your own host if you're self hosting the OneUptime platform. - You can find the secret key on OneUptime Dashboard. Click on "View Monitor" and go to "Settings" tab. ```bash -oneuptime-infrastructure-agent install --secret-key=YOUR_SECRET_KEY --oneuptime-url=https://oneuptime.com +oneuptime-infrastructure-agent configure --secret-key=YOUR_SECRET_KEY --oneuptime-url=https://oneuptime.com ``` ## Starting the agent diff --git a/InfrastructureAgent/install.sh b/InfrastructureAgent/install.sh index f85c02c1dc..2594b41beb 100644 --- a/InfrastructureAgent/install.sh +++ b/InfrastructureAgent/install.sh @@ -74,4 +74,4 @@ if [ ! -x "${BINDIR}/oneuptime-infrastructure-agent" ]; then exit 1 fi -echo "oneuptime-infrastructure-agent installed successfully to ${BINDIR}" \ No newline at end of file +echo "oneuptime-infrastructure-agent installed successfully to ${BINDIR}. Please configure the agent using 'oneuptime-infrastructure-agent configure'." \ No newline at end of file diff --git a/InfrastructureAgent/main.go b/InfrastructureAgent/main.go index 87f2ec6e6c..54d8139093 100644 --- a/InfrastructureAgent/main.go +++ b/InfrastructureAgent/main.go @@ -66,7 +66,7 @@ func main() { svcConfig := &service.Config{ Name: "oneuptime-infrastructure-agent", DisplayName: "OneUptime Infrastructure Agent", - Description: "The OneUptime Infrastructure Agent is a lightweight, open-source agent that collects system metrics and sends them to the OneUptime platform. It is designed to be easy to install and use, and to be extensible.", + Description: "The OneUptime Infrastructure Agent is a lightweight, open-source agent that collects system metrics and sends them to the OneUptime platform. It is designed to be easy to configure and use, and to be extensible.", Arguments: []string{"run"}, } @@ -90,8 +90,8 @@ func main() { if len(os.Args) > 1 { cmd := os.Args[1] switch cmd { - case "install": - installFlags := flag.NewFlagSet("install", flag.ExitOnError) + case "configure": + installFlags := flag.NewFlagSet("configure", flag.ExitOnError) secretKey := installFlags.String("secret-key", "", "Secret key (required)") oneuptimeURL := installFlags.String("oneuptime-url", "", "Oneuptime endpoint root URL (required)") err := installFlags.Parse(os.Args[2:]) @@ -102,7 +102,7 @@ func main() { prg.config.SecretKey = *secretKey prg.config.OneUptimeURL = *oneuptimeURL if prg.config.SecretKey == "" || prg.config.OneUptimeURL == "" { - slog.Error("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 'configure' command") os.Exit(2) } // save configuration @@ -113,7 +113,7 @@ func main() { } // Install the service if err := s.Install(); err != nil { - slog.Error("Failed to install service: ", err) + slog.Error("Failed to configure service: ", err) os.Exit(2) } fmt.Println("Service installed. Run the service using 'oneuptime-infrastructure-agent start'") @@ -121,7 +121,7 @@ func main() { case "start": err := prg.config.loadConfig() if os.IsNotExist(err) { - slog.Error("Service configuration not found. Please run 'oneuptime-infrastructure-agent install' to install the service.") + slog.Error("Service configuration not found. Please run 'oneuptime-infrastructure-agent configure' to configure the service.") os.Exit(2) } if err != nil { @@ -129,7 +129,7 @@ func main() { os.Exit(2) } if err != nil || prg.config.SecretKey == "" || prg.config.OneUptimeURL == "" { - slog.Error("Service configuration not found or is incomplete. Please run 'oneuptime-infrastructure-agent install' to install the service.") + slog.Error("Service configuration not found or is incomplete. Please run 'oneuptime-infrastructure-agent configure' to configure the service.") os.Exit(2) } err = s.Start() @@ -143,7 +143,7 @@ func main() { case "run": err := prg.config.loadConfig() if os.IsNotExist(err) { - slog.Error("Service configuration not found. Please run 'oneuptime-infrastructure-agent install' to install the service.") + slog.Error("Service configuration not found. Please run 'oneuptime-infrastructure-agent configure' to configure the service.") os.Exit(2) } if err != nil { @@ -151,7 +151,7 @@ func main() { os.Exit(2) } if err != nil || prg.config.SecretKey == "" || prg.config.OneUptimeURL == "" { - slog.Error("Service configuration not found or is incomplete. Please run 'oneuptime-infrastructure-agent install' to install the service.") + slog.Error("Service configuration not found or is incomplete. Please run 'oneuptime-infrastructure-agent configure' to configure the service.") os.Exit(2) } err = s.Run() @@ -188,13 +188,13 @@ func main() { // add help command case "help": - fmt.Println("Usage: oneuptime-infrastructure-agent install | uninstall | start | stop | restart") + fmt.Println("Usage: oneuptime-infrastructure-agent configure | uninstall | start | stop | restart") default: slog.Error("Invalid command") os.Exit(2) } } else { - fmt.Println("Usage: oneuptime-infrastructure-agent install | uninstall | start | stop | restart") + fmt.Println("Usage: oneuptime-infrastructure-agent configure | uninstall | start | stop | restart") } }