Skip to content

Commit

Permalink
Fix feedback from #87
Browse files Browse the repository at this point in the history
This commit applies the feedback given in #87 and uses a flag
to both add documentation and to match the style of the rest
of the project.

This change is only useful for exec healthchecks and not for
http probes. Wherever possible users should only use http
healthchecks since exec is very resource intensive.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Nov 28, 2019
1 parent f846f56 commit b6e635e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ var (
)

func main() {
var runHealthcheck bool

flag.BoolVar(&runHealthcheck,
"run-healthcheck",
false,
"Check for the a lock-file, when using an exec healthcheck. Exit 0 for present, non-zero when not found.")

flag.Parse()

switch flag.Arg(0) {
case "healthcheck":
if runHealthcheck {
if lockFilePresent() {
os.Exit(0)
}

fmt.Fprintf(os.Stderr, "unable to find lock file.\n")
os.Exit(1)
}

Expand Down Expand Up @@ -367,6 +374,7 @@ func makeStaticRequestHandler(watchdogConfig config.WatchdogConfig) http.Handler

func lockFilePresent() bool {
path := filepath.Join(os.TempDir(), ".lock")

if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
Expand Down

0 comments on commit b6e635e

Please sign in to comment.