Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --health-check command line switch #1725

Merged
merged 6 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
bugficks marked this conversation as resolved.
Show resolved Hide resolved
}
os.Exit(0)
}

if rollingRestart && monitorOnly {
log.Fatal("Rolling restarts is not compatible with the global monitor only flag")
Expand Down
3 changes: 3 additions & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ COPY --from=alpine \
EXPOSE 8080

COPY watchtower /

HEALTHCHECK CMD [ "/watchtower", "--health-check"]

ENTRYPOINT ["/watchtower"]
2 changes: 2 additions & 0 deletions dockerfiles/Dockerfile.dev-self-contained
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions dockerfiles/Dockerfile.self-contained
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
13 changes: 12 additions & 1 deletion docs/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

bugficks marked this conversation as resolved.
Show resolved Hide resolved
Run health check and exit.

```text
Argument: --health-check
Environment Variable: WATCHTOWER_HEALTH_CHECK
Possible values: -
bugficks marked this conversation as resolved.
Show resolved Hide resolved
Default: -
```
6 changes: 6 additions & 0 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
bugficks marked this conversation as resolved.
Show resolved Hide resolved
"Do health check and exit")
}

// RegisterNotificationFlags that are used by watchtower to send notifications
Expand Down
Loading