Пример #1
0
func startUnitAction(c *cli.Context) {
	r := getRegistry(c)

	cliRequirements := parseRequirements(c.String("require"))

	payloads := make([]job.JobPayload, len(c.Args()))
	for i, v := range c.Args() {
		out, err := ioutil.ReadFile(v)
		if err != nil {
			fmt.Printf("%s: No such file or directory\n", v)
			return
		}

		unitFile := unit.NewSystemdUnitFile(string(out))
		fileRequirements := unitFile.Requirements()
		requirements := stackRequirements(fileRequirements, cliRequirements)

		name := path.Base(v)
		payload, err := job.NewJobPayload(name, unitFile.String(), requirements)
		if err != nil {
			fmt.Println(err.Error())
			return
		} else {
			payloads[i] = *payload
		}
	}

	req, err := job.NewJobRequest(payloads)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	r.AddRequest(req)
}
Пример #2
0
// Private helper method that takes a path to an Etcd directory and returns
// all of the items as job.Job objects.
func (r *Registry) getJobsAtPath(key string) map[string]job.Job {
	resp, err := r.Etcd.Get(key, false)

	// Assume the error was KeyNotFound and return an empty data structure
	if err != nil {
		return make(map[string]job.Job, 0)
	}

	jobs := make(map[string]job.Job, len(resp.Kvs))
	for _, kv := range resp.Kvs {
		_, name := path.Split(kv.Key)
		payload := job.NewJobPayload(kv.Value)
		job := job.NewJob(name, nil, payload)
		jobs[job.Name] = *job
	}

	return jobs
}
Пример #3
0
func (t *Target) GetJobs() map[string]job.Job {
	object := unitPath(t.GetSystemdTargetName())
	info, err := t.Systemd.GetUnitInfo(object)

	if err != nil {
		panic(err)
	}

	names := info["Wants"].Value().([]string)
	jobs := make(map[string]job.Job, len(names))

	for _, name := range names {
		payload := job.NewJobPayload(readUnit(name))
		name = strings.TrimSuffix(name, ".service")
		state := t.GetJobState(name)
		jobs[name] = *job.NewJob(name, state, payload)
	}

	return jobs
}