示例#1
0
func (c *Start) Run(context *cmd.Context) error {
	log.Infof("vertice.")
	config, err := c.ParseConfig(c.file.String())

	if err != nil {
		log.WithFields(log.Fields{
			"error": err.Error(),
		}).Fatal("Failed to parse config")
		return fmt.Errorf("Failed to parse config: %s", err)
	}

	cmd := NewCommand()
	cmd.Version = "1.0"

	if err := cmd.Megd(config, cmd.Version); err != nil {
		return fmt.Errorf("run: %s", err)
	}

	signalCh := make(chan os.Signal, 1)
	signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)

	select {
	case <-signalCh:
		log.Info("signal received, initializing clean shutdown...")
		go func() {
			cmd.Close()
		}()
	}

	// Block again until another signal is received, a shutdown timeout elapses,
	// or the Command is gracefully closed
	log.Warn("waiting for clean shutdown...")
	select {
	case <-signalCh:
		log.Info("second signal received, initializing hard shutdown")
	case <-time.After(time.Second * 30):
		log.Info("time limit reached, initializing hard shutdown")
	case <-cmd.Closed:
		log.Info("server shutdown completed")
	}
	// goodbye.
	return nil
}
示例#2
0
func (c *Start) Run(context *cmd.Context) error {
	log.Infof("gulpd.")

	config, err := c.ParseConfig(c.file.String())
	if err != nil {
		return fmt.Errorf("parse config: %s", err)
	}
	cmd := NewCommand()
	cmd.Version = "0.9.2"

	if err := cmd.Gpd(config, cmd.Version); err != nil {
		return fmt.Errorf("run: %s", err)
	}

	signalCh := make(chan os.Signal, 1)
	signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
	fmt.Println("Listening for signals")

	// Block until one of the signals above is received
	select {
	case <-signalCh:
		fmt.Println("Signal received, initializing clean shutdown...")
		go func() {
			cmd.Close()
		}()
	}

	// Block again until another signal is received, a shutdown timeout elapses,
	// or the Command is gracefully closed
	fmt.Println("Waiting for clean shutdown...")
	select {
	case <-signalCh:
		fmt.Println("second signal received, initializing hard shutdown")
	case <-time.After(time.Second * 30):
		fmt.Println("time limit reached, initializing hard shutdown")
	case <-cmd.Closed:
		fmt.Println("server shutdown completed")
	}
	// goodbye.
	return nil
}