2020-02-04 13:48:33 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-10-28 17:15:13 +02:00
|
|
|
"io"
|
2020-02-04 13:48:33 +02:00
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2021-04-26 13:52:50 +02:00
|
|
|
|
2021-09-30 16:23:30 +02:00
|
|
|
"github.com/imgproxy/imgproxy/v3/config"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/config/configurators"
|
2020-02-04 13:48:33 +02:00
|
|
|
)
|
|
|
|
|
2020-02-27 17:44:59 +02:00
|
|
|
func healthcheck() int {
|
2021-04-26 13:52:50 +02:00
|
|
|
network := config.Network
|
|
|
|
bind := config.Bind
|
2021-11-23 11:09:50 +02:00
|
|
|
pathprefix := config.PathPrefix
|
2020-02-04 13:48:33 +02:00
|
|
|
|
2021-04-26 13:52:50 +02:00
|
|
|
configurators.String(&network, "IMGPROXY_NETWORK")
|
|
|
|
configurators.String(&bind, "IMGPROXY_BIND")
|
2023-05-17 16:47:20 +02:00
|
|
|
configurators.URLPath(&pathprefix, "IMGPROXY_PATH_PREFIX")
|
2020-02-04 13:48:33 +02:00
|
|
|
|
|
|
|
httpc := http.Client{
|
|
|
|
Transport: &http.Transport{
|
|
|
|
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
|
|
|
|
return net.Dial(network, bind)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-11-23 11:09:50 +02:00
|
|
|
res, err := httpc.Get(fmt.Sprintf("http://imgproxy%s/health", pathprefix))
|
2020-02-04 13:48:33 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err.Error())
|
2020-02-27 17:44:59 +02:00
|
|
|
return 1
|
2020-02-04 13:48:33 +02:00
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
2022-10-28 17:15:13 +02:00
|
|
|
msg, _ := io.ReadAll(res.Body)
|
2020-02-04 13:48:33 +02:00
|
|
|
fmt.Fprintln(os.Stderr, string(msg))
|
|
|
|
|
|
|
|
if res.StatusCode != 200 {
|
2020-02-27 17:44:59 +02:00
|
|
|
return 1
|
2020-02-04 13:48:33 +02:00
|
|
|
}
|
|
|
|
|
2020-02-27 17:44:59 +02:00
|
|
|
return 0
|
2020-02-04 13:48:33 +02:00
|
|
|
}
|