container_discovery/main.go

58 lines
1.1 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"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants"
"git.loafle.net/overflow/container_discovery/server"
)
var (
pidFilePath *string
)
func init() {
pidFilePath = flag.String(ocpcc.FlagPidFilePathName, "./dist/discovery.pid", "PID file path")
loggingConfigFilePath := flag.String(ocpcc.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)
}
}