mirror of
https://github.com/traefik/traefik.git
synced 2025-08-07 23:27:11 +02:00
Add url option to healthcheck command
This commit is contained in:
parent
85ea8c7b2d
commit
f8933c21e8
@ -2,6 +2,7 @@ package healthcheck
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -22,11 +23,26 @@ func NewCmd(traefikConfiguration *static.Configuration, loaders []cli.ResourceLo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCmd(traefikConfiguration *static.Configuration) func(_ []string) error {
|
func runCmd(traefikConfiguration *static.Configuration) func(args []string) error {
|
||||||
return func(_ []string) error {
|
return func(args []string) error {
|
||||||
|
fs := flag.NewFlagSet("healthcheck", flag.ContinueOnError)
|
||||||
|
urlFlag := fs.String("url", "", "")
|
||||||
|
fs.SetOutput(os.Stderr)
|
||||||
|
if err := fs.Parse(args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
traefikConfiguration.SetEffectiveConfiguration()
|
traefikConfiguration.SetEffectiveConfiguration()
|
||||||
|
|
||||||
resp, errPing := Do(*traefikConfiguration)
|
var resp *http.Response
|
||||||
|
var errPing error
|
||||||
|
if *urlFlag != "" {
|
||||||
|
client := &http.Client{Timeout: 5 * time.Second}
|
||||||
|
resp, errPing = client.Head(*urlFlag)
|
||||||
|
} else {
|
||||||
|
resp, errPing = Do(*traefikConfiguration)
|
||||||
|
}
|
||||||
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,16 @@ $ traefik healthcheck
|
|||||||
OK: http://:8082/ping
|
OK: http://:8082/ping
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### URL Option
|
||||||
|
|
||||||
|
The URL to check can be specified with the `--url` flag, which defaults to `http://localhost:8080/ping`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
traefik healthcheck --url=http://localhost:8080/ping
|
||||||
|
```
|
||||||
|
|
||||||
## Ping
|
## Ping
|
||||||
|
|
||||||
The `/ping` health-check URL is enabled with the command-line `--ping` or config file option `[ping]`.
|
The `/ping` health-check URL is enabled with the command-line `--ping` or config file option `[ping]`.
|
||||||
|
Loading…
Reference in New Issue
Block a user