-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (52 loc) · 1.3 KB
/
main.go
File metadata and controls
68 lines (52 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) OpenFaaS Author(s) 2021. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/openfaas/of-watchdog/config"
"github.com/openfaas/of-watchdog/pkg"
)
func main() {
var runHealthcheck bool
var versionFlag bool
flag.BoolVar(&versionFlag, "version", false, "Print the version and exit")
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()
printVersion()
if versionFlag {
return
}
watchdogConfig, err := config.New(os.Environ())
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading config: %s", err.Error())
os.Exit(1)
}
w := pkg.NewWatchdog(watchdogConfig)
if runHealthcheck {
if w.LockFilePresent() {
os.Exit(0)
}
fmt.Fprintf(os.Stderr, "unable to find lock file.\n")
os.Exit(1)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := w.Start(ctx); err != nil {
log.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
}
func printVersion() {
sha := "unknown"
if len(GitCommit) > 0 {
sha = GitCommit
}
log.Printf("Version: %v\tSHA: %v\n", BuildVersion(), sha)
}