Exemplo n.º 1
0
// 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.ProvisionedUnits() {
			agent := fmt.Sprintf("juju-%s", strings.Join(strings.Split(u.GetName(), "/"), "-"))
			if u.GetStatus() == provision.StatusDown {
				log.Debugf("Healing %s", agent)
				upStartCmd("stop", agent, u.GetIp())
				upStartCmd("start", agent, u.GetIp())
			}
		}
	}
	return nil
}
Exemplo n.º 2
0
// 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.ProvisionedUnits() {
			args := []string{"-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "grep", dns, "/etc/init/juju-machine-agent.conf"}
			err := executor().Execute("ssh", args, nil, nil, nil)
			if err != nil {
				log.Debugf("Injecting bootstrap private dns for machine %d", u.GetMachine())
				args = []string{"-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"}
				executor().Execute("ssh", args, nil, nil, nil)
			}
			agent := fmt.Sprintf("/etc/init/juju-%s.conf", strings.Join(strings.Split(u.GetName(), "/"), "-"))
			args = []string{"-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "grep", dns, agent}
			err = executor().Execute("ssh", args, nil, nil, nil)
			if err != nil {
				log.Debugf("Injecting bootstrap private dns for agent %s", agent)
				args = []string{"-o", "StrictHostKeyChecking no", "-q", "-l", "ubuntu", u.GetIp(), "sudo", "sed", "-i", "'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\"" + dns + ":2181\"/g'", agent}
				executor().Execute("ssh", args, nil, nil, nil)
			}
		}
	}
	return nil
}