mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-06-18 05:00:03 +02:00
Adding getopts package to parse pid file path.
This commit is contained in:
parent
83688c4b48
commit
2b823c1dd3
2 changed files with 17 additions and 3 deletions
3
Makefile
3
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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue