Esempio n. 1
0
func (svc *service) Run() (string, error) {
	logger := logrus.New()
	err := setupSyslog(logger)
	if err != nil {
		return "Could not create syslog", err
	}

	// load configuration file
	config, err := config.LoadFromFile(svc.args["<config-file>"].(string))
	if err != nil {
		logger.WithError(err).Error("Failed to open configuration file")
		return "Failed to open configuration file", err
	}

	w, err := worker.New(config, logger)
	if err != nil {
		logger.WithError(err).Error("Could not create worker")
		return "Could not create worker", err
	}

	sigTerm := make(chan os.Signal, 1)
	signal.Notify(sigTerm, os.Interrupt, os.Kill, syscall.SIGTERM)
	go func() {
		<-sigTerm
		w.Stop()
	}()
	w.Start()
	return "Worker successfully started", nil
}
Esempio n. 2
0
func (cmd) Execute(args map[string]interface{}) bool {
	config, err := config.LoadFromFile(args["<config.yml>"].(string))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return false
	}

	w, err := worker.New(config, nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return false
	}

	done := make(chan struct{})
	go func() {
		w.Start()
		close(done)
	}()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	select {
	case <-c:
		signal.Stop(c)
		w.Stop()
		<-done
	case <-done:
	}

	return true
}