container_discovery/main.go

56 lines
1.0 KiB
Go
Raw Normal View History

2018-04-19 11:36:56 +00:00
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
"git.loafle.net/commons/logging-go"
2018-04-26 09:00:24 +00:00
occp "git.loafle.net/overflow/commons-go/config/probe"
2018-05-03 06:30:23 +00:00
"git.loafle.net/overflow/container_discovery/client"
2018-04-19 11:36:56 +00:00
)
var (
2018-05-03 06:30:23 +00:00
portNumber *int
2018-04-19 11:36:56 +00:00
)
func init() {
2018-05-03 08:15:21 +00:00
portNumber = flag.Int(occp.FlagProbePortName, 60000, "Port number of Probe")
2018-04-26 09:00:24 +00:00
loggingConfigFilePath := flag.String(occp.FlagLoggingConfigFilePathName, "", "logging config path")
2018-04-19 11:36:56 +00:00
flag.Parse()
logging.InitializeLogger(*loggingConfigFilePath)
}
func main() {
defer logging.Logger().Sync()
2018-05-03 06:30:23 +00:00
c := client.New(*portNumber)
2018-04-19 11:36:56 +00:00
2018-05-03 08:15:21 +00:00
err := c.Start()
if nil != err {
log.Printf("err: %v", err)
2018-04-19 11:36:56 +00:00
os.Exit(1)
2018-05-03 08:15:21 +00:00
}
2018-04-19 11:36:56 +00:00
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt,
syscall.SIGKILL,
syscall.SIGSTOP,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
<-interrupt
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
2018-05-03 06:30:23 +00:00
if err := c.Stop(ctx); err != nil {
2018-04-19 11:36:56 +00:00
logging.Logger().Errorf("error: %v", err)
}
}