container_network/main.go

58 lines
1.1 KiB
Go
Raw Normal View History

2018-04-19 15:46:38 +00:00
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
"time"
"git.loafle.net/commons/logging-go"
2018-04-26 08:50:26 +00:00
occp "git.loafle.net/overflow/commons-go/config/probe"
2018-04-19 15:46:38 +00:00
"git.loafle.net/overflow/container_network/server"
)
var (
pidFilePath *string
)
func init() {
2018-04-26 08:50:26 +00:00
pidFilePath = flag.String(occp.FlagPidFilePathName, "./dist/network.pid", "PID file path")
loggingConfigFilePath := flag.String(occp.FlagLoggingConfigFilePathName, "", "logging config path")
2018-04-19 15:46:38 +00:00
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)
}
}