From 62e1330e45ecc984061fa6eabd8dc7cb62c2c98c Mon Sep 17 00:00:00 2001 From: Nuno Diegues Date: Thu, 24 Mar 2022 17:19:23 +0000 Subject: [PATCH] TUN-5933: Better messaging to help user when installing service if it is already installed --- cmd/cloudflared/service_template.go | 11 ++++++++++- cmd/cloudflared/windows_service.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/cloudflared/service_template.go b/cmd/cloudflared/service_template.go index 13725648..ad7901d1 100644 --- a/cmd/cloudflared/service_template.go +++ b/cmd/cloudflared/service_template.go @@ -44,7 +44,7 @@ func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error { return err } if _, err = os.Stat(resolvedPath); err == nil { - return fmt.Errorf("cloudflared service is already installed at %s", resolvedPath) + return fmt.Errorf(serviceAlreadyExistsWarn(resolvedPath)) } var buffer bytes.Buffer @@ -75,6 +75,15 @@ func (st *ServiceTemplate) Remove() error { return nil } +func serviceAlreadyExistsWarn(service string) string { + return fmt.Sprintf("cloudflared service is already installed at %s; if you are running a cloudflared tunnel, you "+ + "can point it to multiple origins, avoiding the need to run more than one cloudflared service in the "+ + "same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean "+ + "up the existing service and then try again this command", + service, + ) +} + func runCommand(command string, args ...string) error { cmd := exec.Command(command, args...) stderr, err := cmd.StderrPipe() diff --git a/cmd/cloudflared/windows_service.go b/cmd/cloudflared/windows_service.go index 6d12191a..79b7f431 100644 --- a/cmd/cloudflared/windows_service.go +++ b/cmd/cloudflared/windows_service.go @@ -191,7 +191,7 @@ func installWindowsService(c *cli.Context) error { log := zeroLogger.With().Str(LogFieldWindowsServiceName, windowsServiceName).Logger() if err == nil { s.Close() - return fmt.Errorf("Service %s already exists", windowsServiceName) + return fmt.Errorf(serviceAlreadyExistsWarn(windowsServiceName)) } extraArgs, err := getServiceExtraArgsFromCliArgs(c, &log) if err != nil {