Exemple #1
0
func (sup *Supervisor) acceptAgent(cc net.Conn) {
	sup.mu.Lock()
	defer sup.mu.Unlock()

	raddr := addressFromNet(cc.RemoteAddr())
	ll := log.KV("raddr", raddr)

	if _, ok := sup.agents[raddr]; ok {
		ll.Info("agent already joined")
		_ = cc.Close()
		return
	}
	ll.Info("new agent joined")

	agent := &agent{
		ll:       ll,
		addr:     raddr,
		client:   rpc.RepresentAgent(cc, sup.provider),
		cc:       cc,
		setState: make(chan stack),
	}
	sup.agents[raddr] = agent

	if s, ok := sup.dfn.Machines[raddr]; !ok {
		ll.Info("no stack defined for this agent")
	} else {
		go agent.enforceState(s)
	}
}
Exemple #2
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")
		}
	}
}
Exemple #3
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!")
}
Exemple #4
0
func main() {
	ll := log.KV("app", appName)
	ll.Info("starting")

	l, err := net.Listen("tcp", ":1337")
	if err != nil {
		ll.Err(err).Fatal("can't listen")
	}
	defer l.Close()

	acceptAgents(ll.KV("listen.addr", l.Addr().String()), l)
}
func (mproc *managedProcess) handleError(err error) {
	log.KV("proc.id", mproc.proc.ID()).Err(err).Error("unexpected error")
}