container_network/main.go
crusader f28ff9a303 ing
2018-04-20 00:46:38 +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"
ocpcc "git.loafle.net/overflow/commons-go/probe/constants"
"git.loafle.net/overflow/container_network/server"
)
var (
pidFilePath *string
)
func init() {
pidFilePath = flag.String(ocpcc.FlagPidFilePathName, "./dist/network.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)
}
}