mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-11 04:32:29 +02:00
imgproxy health command
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
### Added
|
### Added
|
||||||
- `IMGPROXY_NETWORK` config. Allows to bind on Unix socket.
|
- `IMGPROXY_NETWORK` config. Allows to bind on Unix socket.
|
||||||
- `IMGPROXY_CACHE_CONTROL_PASSTHROUGH` config.
|
- `IMGPROXY_CACHE_CONTROL_PASSTHROUGH` config.
|
||||||
|
- `imgproxy health` command.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix detection of SVG starting with a comment.
|
- Fix detection of SVG starting with a comment.
|
||||||
|
@@ -5,3 +5,15 @@ imgproxy comes with a built-in health check HTTP endpoint at `/health`.
|
|||||||
`GET /health` returns HTTP Status `200 OK` if the server is started successfully.
|
`GET /health` returns HTTP Status `200 OK` if the server is started successfully.
|
||||||
|
|
||||||
You can use this for readiness/liveness probe when deploying with a container orchestration system such as Kubernetes.
|
You can use this for readiness/liveness probe when deploying with a container orchestration system such as Kubernetes.
|
||||||
|
|
||||||
|
## imgproxy health
|
||||||
|
|
||||||
|
imgproxy provides `imgproxy health` command that makes an HTTP request to the health endpoint based on `IMGPROXY_BIND` and `IMGPROXY_NETWORK` configs. It exits with `0` when the request is successful and with `1` otherwise. The command is handy to use with Docker Compose:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
healthcheck:
|
||||||
|
test: [ "CMD", "imgproxy", "health" ]
|
||||||
|
timeout: 10s
|
||||||
|
interval: 10s
|
||||||
|
retries: 3
|
||||||
|
```
|
||||||
|
42
healthcheck.go
Normal file
42
healthcheck.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func healthcheck() {
|
||||||
|
network := conf.Network
|
||||||
|
bind := conf.Bind
|
||||||
|
|
||||||
|
strEnvConfig(&network, "IMGPROXY_NETWORK")
|
||||||
|
strEnvConfig(&bind, "IMGPROXY_BIND")
|
||||||
|
|
||||||
|
httpc := http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
|
||||||
|
return net.Dial(network, bind)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := httpc.Get("http://imgproxy/health")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
msg, _ := ioutil.ReadAll(res.Body)
|
||||||
|
fmt.Fprintln(os.Stderr, string(msg))
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
Reference in New Issue
Block a user