func main() { flag.Parse() if *versionFlag { fmt.Println(VERSION) os.Exit(0) } if *logstashFlag { log.ChangeToLogstashFormater(APP_NAME) } log.SetLogFile(LOG_FILE) err := config.LoadConfig(*cfgFileFlag) if err != nil { log.Fatalln(err) } pid := os.Getpid() // Save the pid into the pid file. err = utils.WriteFile(PID_FILE, []byte(strconv.Itoa(pid)), 0644) if err != nil { log.Fatalln(err) } defer os.Remove(PID_FILE) go api.Start() // catch some signal sigCh := make(chan os.Signal) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, os.Kill) // Block until a signal is received. s := <-sigCh log.Debugf("Caught Signal: %s, shutting down...", s) }
func main() { flag.Parse() if *versionFlag { fmt.Println(VERSION) os.Exit(0) } if *logstashFlag { log.ChangeToLogstashFormater(APP_NAME) } log.SetLogFile(LOG_FILE) err := config.LoadConfig(*cfgFileFlag) if err != nil { log.Fatalln(err) } pid := os.Getpid() // This process's pid. // Save the pid into the pid file. err = utils.WriteFile(PID_FILE, []byte(strconv.Itoa(pid)), 0666) if err != nil { log.Fatalln(err) } defer os.Remove(PID_FILE) clientSet, err := initClientSet() if err != nil { log.Fatalln(err) } go engine.Boot() engine.Watcher, err = engine.NewWatch(clientSet) if err != nil { log.Fatalln(err) } go engine.Run() if engine.CurrentDir == "" { log.Fatalln("current directory is blank.") } err = utils.WriteFile(path.Join(path.Dir(engine.CurrentDir), ".version"), []byte(VERSION), 0644) if err != nil { log.Fatalln(err) } err = common.ConsulRegister(APP_NAME, path.Join(engine.CurrentDir, "deploy")) if err != nil { log.Fatalln(err) } // go api.Start() // catch some signal sigCh := make(chan os.Signal) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM, os.Kill) // Block until a signal is received. s := <-sigCh log.Infof("Caught Signal: %s, shutting down...", s) }