container_network/main.go
crusader ba176f57f3 ing
2018-05-03 18:54:38 +09:00

56 lines
1.0 KiB
Go

package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
"git.loafle.net/commons/logging-go"
occp "git.loafle.net/overflow/commons-go/config/probe"
"git.loafle.net/overflow/container_network/client"
)
var (
portNumber *int
)
func init() {
portNumber = flag.Int(occp.FlagProbePortName, 60000, "Port number of Probe")
loggingConfigFilePath := flag.String(occp.FlagLoggingConfigFilePathName, "", "logging config path")
flag.Parse()
logging.InitializeLogger(*loggingConfigFilePath)
}
func main() {
defer logging.Logger().Sync()
c := client.New(*portNumber)
err := c.Start()
if nil != err {
log.Printf("err: %v", err)
os.Exit(1)
}
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()
if err := c.Stop(ctx); err != nil {
logging.Logger().Errorf("error: %v", err)
}
}