bilibili-backup/app/service/main/workflow/cmd/main.go
2019-04-22 02:59:20 +00:00

51 lines
1.0 KiB
Go

package main
import (
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/service/main/workflow/conf"
"go-common/app/service/main/workflow/http"
"go-common/app/service/main/workflow/service"
"go-common/library/log"
"go-common/library/net/trace"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
log.Error("conf.Init() error(%v)", err)
panic(err)
}
// init log
log.Init(conf.Conf.Log)
defer trace.Close()
defer log.Close()
log.Info("workflow-service start")
// init server
svr := service.New(conf.Conf)
// init http
http.Init(conf.Conf, svr)
// init signal
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("workflow-service get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
svr.Close()
time.Sleep(1 * time.Second)
log.Info("workflow-service exit")
return
case syscall.SIGHUP:
// TODO reload
default:
return
}
}
}