Beispiel #1
0
func (r *Stop) Run(env *goansible.CommandEnv) (*goansible.Result, error) {
	conn, err := us.Dial()
	if err != nil {
		return nil, err
	}

	job, err := conn.Job(r.Name)
	if err != nil {
		return nil, err
	}

	err = job.Stop()
	if err != nil {
		if strings.Index(err.Error(), "Unknown instance") == 0 {
			res := goansible.NewResult(false)
			res.Add("name", r.Name)

			return res, nil
		}
	}

	res := goansible.NewResult(true)
	res.Add("name", r.Name)

	return res, nil
}
Beispiel #2
0
func (r *Restart) Run(env *goansible.CommandEnv) (*goansible.Result, error) {
	conn, err := us.Dial()
	if err != nil {
		return nil, err
	}

	job, err := conn.Job(r.Name)
	if err != nil {
		return nil, err
	}

	inst, err := job.Restart()
	if err != nil {
		return nil, err
	}

	pid, err := inst.Pid()
	if err != nil {
		return nil, err
	}

	res := goansible.NewResult(true)
	res.Add("name", r.Name)
	res.Add("pid", pid)

	return res, nil
}
Beispiel #3
0
func (r *Start) Run(env *goansible.CommandEnv) (*goansible.Result, error) {
	conn, err := us.Dial()
	if err != nil {
		return nil, err
	}

	var ienv []string

	for k, v := range r.Env {
		ienv = append(ienv, fmt.Sprintf("%s=%s", k, v))
	}

	job, err := conn.Job(r.Name)
	if err != nil {
		return nil, err
	}

	inst, err := job.StartWithOptions(ienv, true)
	if err != nil {
		if strings.Index(err.Error(), "Job is already running") == 0 {
			res := goansible.NewResult(false)
			res.Add("name", r.Name)

			return res, nil
		}
		return nil, err
	}

	pid, err := inst.Pid()
	if err != nil {
		return nil, err
	}

	res := goansible.NewResult(true)
	res.Add("name", r.Name)
	res.Add("pid", pid)

	return res, nil
}