diff --git a/Makefile b/Makefile index 35b3858..51e5971 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,8 @@ PROGRAM_NAME=eosio-api-healthcheck SOURCES=src/server.go DEPENDANCIES= github.com/firstrow/tcp_server \ github.com/liamylian/jsontime/v2 \ - github.com/imroc/req + github.com/imroc/req \ + github.com/pborman/getopt/v2 all: build build: build/$(PROGRAM_NAME) diff --git a/src/server.go b/src/server.go index 4283f9f..3f29fbc 100644 --- a/src/server.go +++ b/src/server.go @@ -1,7 +1,6 @@ package main import ( - "os" "fmt" "time" "strings" @@ -10,6 +9,7 @@ import ( "./haproxy" "./eosapi" "github.com/firstrow/tcp_server" + "github.com/pborman/getopt/v2" ) // check_api - Validates head block time. @@ -79,6 +79,11 @@ func check_api_v2(url string, offset int64) (haproxy.HealthCheckStatus, string) return haproxy.HealthCheckUp, "OK" } +// Command line flags +// --------------------------------------------------------- + +var pidFile string + // argv_listen_addr // Parse listen address from command line. // --------------------------------------------------------- @@ -86,7 +91,7 @@ func argv_listen_addr() string { var addr string - argv := os.Args[1:] + argv := getopt.Args() if len(argv) > 0 { addr = argv[0] } else { @@ -107,6 +112,14 @@ func argv_listen_addr() string { // --------------------------------------------------------- func main() { + // Command line parsing + getopt.FlagLong(&pidFile, "pid", 'p', "Path to pid file", "file") + getopt.Parse() + + if len(pidFile) > 0 { + log.Info("Writing pidfile: %s", pidFile) + } + server := tcp_server.New(argv_listen_addr()) // TCP Client connect.