container_discovery/main.go
crusader 7d2e8170d7 ing
2018-04-26 18:00:24 +09:00

58 lines
1.1 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_discovery/server"
)
var (
pidFilePath *string
)
func init() {
pidFilePath = flag.String(occp.FlagPidFilePathName, "./dist/discovery.pid", "PID file path")
loggingConfigFilePath := flag.String(occp.FlagLoggingConfigFilePathName, "", "logging config path")
flag.Parse()
logging.InitializeLogger(*loggingConfigFilePath)
}
func main() {
defer logging.Logger().Sync()
s := server.New(*pidFilePath)
go func() {
err := s.ListenAndServe()
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 := s.Shutdown(ctx); err != nil {
logging.Logger().Errorf("error: %v", err)
}
}