示例#1
0
文件: main.go 项目: ahjdzx/dis
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)
}
示例#2
0
文件: api.go 项目: ahjdzx/dis
func Start() {
	if !config.AppConfig().Http.Enabled {
		return
	}
	addr := config.AppConfig().Http.Listen
	if addr == "" {
		return
	}
	server := &http.Server{
		Addr:    addr,
		Handler: initRouter(),
	}

	log.Infoln("http listening on ", addr)
	log.Fatalln(server.ListenAndServe())
}
示例#3
0
文件: main.go 项目: ahjdzx/dis
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)
}