aboutsummaryrefslogtreecommitdiff
path: root/cmd/anubis/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/anubis/main.go')
-rw-r--r--cmd/anubis/main.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmd/anubis/main.go b/cmd/anubis/main.go
index 9b39aab..69be826 100644
--- a/cmd/anubis/main.go
+++ b/cmd/anubis/main.go
@@ -42,6 +42,7 @@ var (
robotsTxt = flag.Bool("serve-robots-txt", false, "serve a robots.txt file that disallows all robots")
policyFname = flag.String("policy-fname", "", "full path to anubis policy document (defaults to a sensible built-in policy)")
target = flag.String("target", "http://localhost:3923", "target to reverse proxy to")
+ healthcheck = flag.Bool("healthcheck", false, "run a health check against Anubis")
//go:embed static botPolicies.json
static embed.FS
@@ -84,9 +85,30 @@ const (
//go:generate zstd -f -k --ultra -22 static/js/main.mjs
//go:generate brotli -fZk static/js/main.mjs
+func doHealthCheck() error {
+ resp, err := http.Get("http://localhost" + *metricsBind + "/metrics")
+ if err != nil {
+ return fmt.Errorf("failed to fetch metrics: %w", err)
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
+ }
+
+ return nil
+}
+
func main() {
internal.HandleStartup()
+ if *healthcheck {
+ if err := doHealthCheck(); err != nil {
+ log.Fatal(err)
+ }
+ return
+ }
+
s, err := New(*target, *policyFname)
if err != nil {
log.Fatal(err)