1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-07-03 11:53:43 +02:00

Adding getopts package to parse pid file path.

This commit is contained in:
Henrik Hautakoski 2020-06-11 18:56:36 +02:00
parent 83688c4b48
commit 2b823c1dd3
2 changed files with 17 additions and 3 deletions

View file

@ -8,7 +8,8 @@ PROGRAM_NAME=eosio-api-healthcheck
SOURCES=src/server.go SOURCES=src/server.go
DEPENDANCIES= github.com/firstrow/tcp_server \ DEPENDANCIES= github.com/firstrow/tcp_server \
github.com/liamylian/jsontime/v2 \ github.com/liamylian/jsontime/v2 \
github.com/imroc/req github.com/imroc/req \
github.com/pborman/getopt/v2
all: build all: build
build: build/$(PROGRAM_NAME) build: build/$(PROGRAM_NAME)

View file

@ -1,7 +1,6 @@
package main package main
import ( import (
"os"
"fmt" "fmt"
"time" "time"
"strings" "strings"
@ -10,6 +9,7 @@ import (
"./haproxy" "./haproxy"
"./eosapi" "./eosapi"
"github.com/firstrow/tcp_server" "github.com/firstrow/tcp_server"
"github.com/pborman/getopt/v2"
) )
// check_api - Validates head block time. // 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" return haproxy.HealthCheckUp, "OK"
} }
// Command line flags
// ---------------------------------------------------------
var pidFile string
// argv_listen_addr // argv_listen_addr
// Parse listen address from command line. // Parse listen address from command line.
// --------------------------------------------------------- // ---------------------------------------------------------
@ -86,7 +91,7 @@ func argv_listen_addr() string {
var addr string var addr string
argv := os.Args[1:] argv := getopt.Args()
if len(argv) > 0 { if len(argv) > 0 {
addr = argv[0] addr = argv[0]
} else { } else {
@ -107,6 +112,14 @@ func argv_listen_addr() string {
// --------------------------------------------------------- // ---------------------------------------------------------
func main() { 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()) server := tcp_server.New(argv_listen_addr())
// TCP Client connect. // TCP Client connect.