Add --health-check command line switch. Fixes #1257

This commit is contained in:
bugficks 2023-08-09 05:54:04 +00:00
parent 7948242260
commit 3acc52ed59
6 changed files with 34 additions and 1 deletions

View file

@ -152,6 +152,15 @@ func Run(c *cobra.Command, names []string) {
enableMetricsAPI, _ := c.PersistentFlags().GetBool("http-api-metrics")
unblockHTTPAPI, _ := c.PersistentFlags().GetBool("http-api-periodic-polls")
apiToken, _ := c.PersistentFlags().GetString("http-api-token")
healthCheck, _ := c.PersistentFlags().GetBool("health-check")
if healthCheck {
// health check should not have pid 1
if os.Getpid() == 1 {
os.Exit(1)
}
os.Exit(0)
}
if rollingRestart && monitorOnly {
log.Fatal("Rolling restarts is not compatible with the global monitor only flag")

View file

@ -17,4 +17,7 @@ COPY --from=alpine \
EXPOSE 8080
COPY watchtower /
HEALTHCHECK CMD [ "/watchtower", "--health-check"]
ENTRYPOINT ["/watchtower"]

View file

@ -35,4 +35,6 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certifi
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /watchtower/watchtower /watchtower
HEALTHCHECK CMD [ "/watchtower", "--health-check"]
ENTRYPOINT ["/watchtower"]

View file

@ -35,4 +35,6 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certifi
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /go/watchtower/watchtower /watchtower
HEALTHCHECK CMD [ "/watchtower", "--health-check"]
ENTRYPOINT ["/watchtower"]

View file

@ -363,4 +363,15 @@ requests and may rate limit pull requests (mainly docker.io).
Environment Variable: WATCHTOWER_WARN_ON_HEAD_FAILURE
Possible values: always, auto, never
Default: auto
```
```
## Health check
Run health check and exit.
```text
Argument: --health-check
Environment Variable: WATCHTOWER_HEALTH_CHECK
Possible values: -
Default: -
```

View file

@ -186,6 +186,12 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
"log-level",
viper.GetString("WATCHTOWER_LOG_LEVEL"),
"The maximum log level that will be written to STDERR. Possible values: panic, fatal, error, warn, info, debug or trace")
flags.BoolP(
"health-check",
"",
viper.IsSet("WATCHTOWER_HEALTH_CHECK"),
"Do health check and exit")
}
// RegisterNotificationFlags that are used by watchtower to send notifications