Esempio n. 1
0
func main() {
	supervisord := flag.String("supervisord", "127.0.0.1:1337", "address where the supervisor can be reached")
	flag.Parse()

	policy := agent.PolicyAllAtOnce()
	policy = agent.PolicyStartBeforeStop(policy)
	policy = agent.PolicyStopTimeout(policy, time.Second)

	ll := log.KV("app", appName)
	ll.Info("starting")
	defer ll.Info("all done")

	client := osprocess.New(osprocess.NopInstaller())
	// client = container.Log(client, log.KV("container", "osprocess"))

	ag := agent.New(client)

	for {
		cc, err := net.DialTimeout("tcp", *supervisord, 10*time.Second)
		if err != nil {
			ll.Err(err).Error("can't dial supervisord")
			continue
		}

		if err := rpc.OperateAgent(ag, client, cc); err != nil {
			ll.Err(err).Error("can't operate agent over RPC")
		}
	}
}
Esempio n. 2
0
func main() {
	policy := agent.PolicyAllAtOnce()
	policy = agent.PolicyStartBeforeStop(policy)
	policy = agent.PolicyStopTimeout(policy, time.Second)

	ll := log.KV("app", appName)
	ll.Info("starting")

	// client, err := docker.New(os.Getenv("DOCKERD_PORT"), "")
	// if err != nil {
	// 	log.Err(err).Fatal("can't create docker client")
	// }
	// client = container.Log(client, log.KV("container", "docker"))

	client := osprocess.New(osprocess.NopInstaller())
	// client = container.Log(client, log.KV("container", "osprocess"))

	img := client.ProgramID("echoer v1")
	ll = ll.KV("program.id", img)

	ag := agent.New(client)
	ll.Info("starting program")
	if _, err := ag.StartProcess(img); err != nil {
		ll.Err(err).Fatal("couldn't start image")
	}
	time.Sleep(3 * time.Second)

	if _, err := ag.StartProcess(img); err != nil {
		ll.Err(err).Fatal("couldn't start image")
	}
	time.Sleep(3 * time.Second)

	ll.Info("restarting")
	if err := ag.RestartProgram(policy, img); err != nil {
		ll.Err(err).Fatal("couldn't restart image")
	}

	ll.Info("restarted, running")
	time.Sleep(3 * time.Second)

	newImg := client.ProgramID("echoer v2")
	ll.Info("upgrading")
	if err := ag.UpgradeProgram(policy, img, newImg); err != nil {
		ll.Err(err).Fatal("couldn't restart image")
	}

	ll.Info("upgraded, running")
	time.Sleep(3 * time.Second)

	ll.Info("stopping all processes")
	if err := ag.StopProgram(newImg, 10*time.Second); err != nil {
		ll.Err(err).Fatal("couldn't stop image")
	}
	ll.Info("all done!")
}