From a1403fe968d8ca3e21b2b9d662c22a8ffe685a20 Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Wed, 29 May 2019 09:34:10 -0700 Subject: [PATCH] Handle exit code on err fixes #96. This change checks the err returned from the StartServer function, and if it exists, passes a non-zero error code through to the urfave/cli framework. This should allow processes like launchd to detect if cloudflared exited gracefully or with an error. --- cmd/cloudflared/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/cloudflared/main.go b/cmd/cloudflared/main.go index a6495584..3c9e3659 100644 --- a/cmd/cloudflared/main.go +++ b/cmd/cloudflared/main.go @@ -127,10 +127,14 @@ func action(version string, shutdownC, graceShutdownC chan struct{}) cli.ActionF tags["hostname"] = c.String("hostname") raven.SetTagsContext(tags) raven.CapturePanic(func() { err = tunnel.StartServer(c, version, shutdownC, graceShutdownC) }, nil) + exitCode := 0 if err != nil { handleError(err) + exitCode = 1 } - return err + // we already handle error printing, so we pass an empty string so we + // don't have to print again. + return cli.Exit("", exitCode) } }