예제 #1
0
파일: healer.go 프로젝트: nedmax/tsuru
// Heal iterates through all juju units verifying if
// a juju-unit-agent is down and heal these machines.
func (h instanceUnitHealer) Heal() error {
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	var apps []app.App
	err = conn.Apps().Find(nil).All(&apps)
	if err != nil {
		return err
	}
	for _, app := range apps {
		for _, u := range app.ProvisionUnits() {
			agent := fmt.Sprintf("juju-%s", strings.Join(strings.Split(u.GetName(), "/"), "-"))
			if u.GetStatus() == provision.StatusDown {
				log.Printf("Healing %s", agent)
				upStartCmd("stop", agent, u.GetIp())
				upStartCmd("start", agent, u.GetIp())
			}
		}
	}
	return nil
}
예제 #2
0
파일: healer.go 프로젝트: nedmax/tsuru
// Heal verifies if the bootstrap private dns is different of the bootstrap
// private dns setted into agents for each machine.
// If the bootstrap private dns is wrong, Heal will injects the correct value.
func (h instanceAgentsConfigHealer) Heal() error {
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	var apps []app.App
	err = conn.Apps().Find(nil).All(&apps)
	if err != nil {
		return err
	}
	dns, err := h.bootstrapPrivateDns()
	if err != nil {
		return err
	}
	for _, app := range apps {
		for _, u := range app.ProvisionUnits() {
			cmd := exec.Command("ssh", "-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "grep", dns, "/etc/init/juju-machine-agent.conf")
			err := cmd.Run()
			if err != nil {
				log.Printf("Injecting bootstrap private dns for machine %d", u.GetMachine())
				cmd := exec.Command("ssh", "-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "sudo", "sed", "-i", "'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\""+dns+":2181\"/g'", "/etc/init/juju-machine-agent.conf")
				cmd.Run()
			}
			agent := fmt.Sprintf("/etc/init/juju-%s.conf", strings.Join(strings.Split(u.GetName(), "/"), "-"))
			cmd = exec.Command("ssh", "-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "grep", dns, agent)
			err = cmd.Run()
			if err != nil {
				log.Printf("Injecting bootstrap private dns for agent %s", agent)
				cmd := exec.Command("ssh", "-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "sudo", "sed", "-i", "'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\""+dns+":2181\"/g'", agent)
				cmd.Run()
			}
		}
	}
	return nil
}