示例#1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	kingpin.Version(getVersion())
	kingpin.MustParse(ro.Parse(os.Args[1:]))
	logger.Configure(*logLevel, "[romulusd] ", os.Stdout)
	logger.Infof("Starting up romulusd version=%s", getVersion())

	ctx, cancel := context.WithCancel(context.Background())
	lb, er := getLBProvider(*provider, ctx)
	if er != nil {
		logger.Fatalf(er.Error())
	}

	kubernetes.Keyspace = normalizeAnnotationsKey(*annoKey)
	ng, er := NewEngine((*kubeAPI).String(), *kubeUser, *kubePass, *kubeSec, lb, *timeout, ctx)
	if er != nil {
		logger.Fatalf(er.Error())
	}

	if er := ng.Start(*selector, *resync); er != nil {
		logger.Fatalf(er.Error())
	}

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
	select {
	case <-sig:
		logger.Infof("Shutting Down...")
		cancel()
		time.Sleep(100 * time.Millisecond)
		os.Exit(0)
	}
}
示例#2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	kingpin.Version(version)
	kingpin.MustParse(app.Parse(os.Args[1:]))
	logger.Configure(*level, "[transmon] ", os.Stdout)
	logger.Infof("Starting transmon version %v", version)

	c, stop := context.WithCancel(context.Background())
	conf, er := config.ReadAndWatch(*conf, c)
	if er != nil {
		logger.Fatalf("Failed to read config: %v", er)
	}

	go workers(conf, c, stop)

	if conf.Cleaner.Enabled {
		go cleaner(conf, c)
	}

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
	select {
	case <-sig:
		logger.Infof("Received interrupt, shutting down...")
		close(sig)
		stop()
		time.Sleep(3 * time.Second)
		os.Exit(0)
	}
}
示例#3
0
func main() {
	app.Version(version)
	command := kingpin.MustParse(app.Parse(os.Args[1:]))
	logger.Configure(*logLevel, "[runchef] ", os.Stdout)

	switch command {
	case enable.FullCommand():
		cli, er := ezd.New(etcdEp, etcdTo)
		if er != nil {
			logger.Fatalf(er.Error())
		}

		if reason, ok := cli.Get(disableKey); ok == nil {
			if er := cli.Delete(disableKey); er != nil {
				logger.Fatalf(er.Error())
			}
			logger.Infof("Chef is now enabled! (Was disabled with reason: %s)", reason)
		} else {
			logger.Infof("Chef is already enabled.")
		}
	case disable.FullCommand():
		cli, er := ezd.New(etcdEp, etcdTo)
		if er != nil {
			logger.Fatalf(er.Error())
		}

		if reason, ok := cli.Get(disableKey); ok == nil {
			logger.Infof("Chef is already disabled with reason: %s", reason)
		} else {
			if er := cli.Set(disableKey, *disableReason); er != nil {
				logger.Fatalf(er.Error())
			}
			logger.Infof("Chef disabled with reason: %s", *disableReason)
		}
	case shell.FullCommand():
		c := *shellImage
		if len(*shellContainer) > 0 {
			c = *shellContainer
			*pullImage = false
		}
		if er := runShell(c, *shellCache, *pullImage); er != nil {
			logger.Fatalf(er.Error())
		}
	case client.FullCommand():
		c := *clientImage
		if len(*clientContainer) > 0 {
			c = *clientContainer
			*pullImage = false
		}
		cli, er := ezd.New(etcdEp, etcdTo)
		if er != nil {
			logger.Fatalf(er.Error())
		}
		if reason, ok := cli.Get(disableKey); ok == nil {
			logger.Infof("Chef is disabled: %v", reason)
			os.Exit(0)
		}
		defer cleanupChef()
		newClientRB(filepath.Join(*chefDir, "client.rb"), *clientName, *clientEnv, *sslVerify).write()
		if er := runChef(c, *clientCache, *clientEnv, *clientRunlist, *clientForceFmt, *clientLocal, *pullImage); er != nil {
			logger.Fatalf(er.Error())
		}
	}
}
示例#4
0
func workers(conf *config.Config, c context.Context, quit context.CancelFunc) {
	var (
		port    = time.NewTicker(portInterval)
		restart = time.NewTicker(restartInterval)
		check   = time.NewTicker(checkInterval)
	)

	logger.Infof("Port update will run once every hour")
	logger.Infof("VPN restart will run once every day")

	trans, er := process.New("transmission", conf.Transmission.Command, os.Stdout)
	if er != nil {
		quit()
		logger.Fatalf(er.Error())
	}
	vpn, er := process.New("openvpn", conf.OpenVPN.Command, os.Stdout)
	if er != nil {
		quit()
		logger.Fatalf(er.Error())
	}

	if er := startProcesses(trans, vpn, conf, c); er != nil {
		quit()
		logger.Fatalf(er.Error())
	}
	portUpdate(conf, c)

	for {
		select {
		case <-c.Done():
			port.Stop()
			restart.Stop()
			trans.Stop()
			vpn.Stop()
			return
		case t := <-check.C:
			logger.Debugf("Checking transmission port at %v", t)
			if er := portCheck(trans, conf, c); er != nil {
				if er := restartProcesses(trans, vpn, conf, c); er != nil {
					port.Stop()
					restart.Stop()
					trans.Stop()
					vpn.Stop()
					logger.Fatalf(er.Error())
				}
			}
		case t := <-port.C:
			logger.Infof("Update of Transmission port at %v", t)
			if er := portUpdate(conf, c); er != nil {
				if er := restartProcesses(trans, vpn, conf, c); er != nil {
					port.Stop()
					restart.Stop()
					trans.Stop()
					vpn.Stop()
					logger.Fatalf(er.Error())
				}
			}
		case t := <-restart.C:
			logger.Infof("Restarting Transmission and OpenVPN at %v", t)
			if er := restartProcesses(trans, vpn, conf, c); er != nil {
				port.Stop()
				restart.Stop()
				trans.Stop()
				vpn.Stop()
				logger.Fatalf(er.Error())
			}
		}
	}
}