2020-02-04 13:48:33 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2020-02-27 17:44:59 +02:00
|
|
|
func healthcheck() int {
|
2020-02-04 13:48:33 +02:00
|
|
|
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())
|
2020-02-27 17:44:59 +02:00
|
|
|
return 1
|
2020-02-04 13:48:33 +02:00
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
msg, _ := ioutil.ReadAll(res.Body)
|
|
|
|
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
|
|
|
}
|