예제 #1
0
func listUnitsAction(c *cli.Context) {
	r := registry.New()

	fmt.Fprintln(out, "UNIT\tLOAD\tACTIVE\tSUB\tDESC\tMACHINE")

	for _, j := range r.GetAllScheduledJobs() {
		js := r.GetJobState(&j)

		loadState := "-"
		activeState := "-"
		subState := "-"
		mach := "-"

		if js != nil {
			loadState = js.LoadState
			activeState = js.ActiveState
			subState = js.SubState
			if js.Machine != nil {
				mach = js.Machine.String()
			}
		}

		fmt.Fprintf(out, "%s\t%s\t%s\t%s\t-\t%s\n", j.Name, loadState, activeState, subState, mach)
	}

	out.Flush()
}
예제 #2
0
파일: coreinit.go 프로젝트: philips/fleet
func main() {
	var bootId string

	f := flag.NewFlagSet(os.Args[0], 1)
	f.StringVar(&bootId, "bootid", "", "Provide a user-generated boot ID. This will override the actual boot ID of the machine.")
	f.Parse(os.Args[1:])

	if bootId == "" {
		bootId = machine.ReadLocalBootId()
	}

	m := machine.New(bootId)
	r := registry.New()
	a := agent.New(r, m, "")

	// Push the initial state to the registry
	a.UpdateJobs()
	a.UpdateMachine()

	// Kick off the heartbeating process
	go a.DoHeartbeat()

	s := scheduler.New(r, m)
	s.DoSchedule()
}
예제 #3
0
func startUnitAction(c *cli.Context) {
	r := registry.New()

	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)
		}

		name := path.Base(v)
		payload := job.JobPayload{name, string(out)}
		if err != nil {
			fmt.Print(err)
		} else {
			payloads[i] = payload
		}
	}

	//TODO: Handle error response from NewJobRequest
	req, _ := job.NewJobRequest(payloads, nil)

	if c.Bool("all-machines") {
		req.SetFlag(job.RequestAllMachines)
		req.Count = 1
	} else {
		req.Count = c.Int("count")
	}

	r.AddRequest(req)
}
예제 #4
0
func statusUnitsAction(c *cli.Context) {
	r := registry.New()

	for i, v := range c.Args() {
		// This extra newline here to match systemctl status output
		if i != 0 {
			fmt.Printf("\n")
		}

		name := path.Base(v)
		j, _ := job.NewJob(name, nil, nil)
		j.State = r.GetJobState(j)

		loadState := "-"
		activeState := "-"
		subState := "-"

		if j.State != nil {
			loadState = j.State.LoadState
			activeState = j.State.ActiveState
			subState = j.State.SubState
		}

		fmt.Printf("%s\n", j.Name)
		fmt.Printf("\tLoaded: %s\n", loadState)
		fmt.Printf("\tActive: %s (%s)\n", activeState, subState)
		if j.State != nil {
			for _, sock := range j.State.Sockets {
				fmt.Printf("\tListen: %s\n", sock)
			}
		}
		fmt.Print("\n")
	}
}
예제 #5
0
파일: stop.go 프로젝트: jamessharp/coreinit
func stopUnitAction(c *cli.Context) {
	r := registry.New()

	for _, v := range c.Args() {
		name := path.Base(v)
		r.RemoveJobWatch(name)
	}
}
예제 #6
0
func New(cfg config.Config) *Server {
	m := machine.New(cfg.BootId)
	r := registry.New()
	es := registry.NewEventStream()

	a := agent.New(r, es, m, "")
	e := engine.New(r, es, m)

	srv := Server{a, e, m, r, es}
	srv.Configure(&cfg)

	return &srv
}
예제 #7
0
파일: server.go 프로젝트: rened/coreinit
func New(cfg config.Config) *Server {
	m := machine.New(cfg.BootId, cfg.PublicIP, cfg.Metadata())

	regClient := etcd.NewClient(cfg.EtcdServers)
	regClient.SetConsistency(etcd.WEAK_CONSISTENCY)
	r := registry.New(regClient)

	eventClient := etcd.NewClient(cfg.EtcdServers)
	eventClient.SetConsistency(etcd.WEAK_CONSISTENCY)
	es := registry.NewEventStream(eventClient, r)
	es.Open()

	a := agent.New(r, es, m, "", cfg.UnitPrefix)
	e := engine.New(r, es, m)

	return &Server{a, e, m, r, es}
}
예제 #8
0
파일: cat.go 프로젝트: jamessharp/coreinit
func printUnitAction(c *cli.Context) {
	r := registry.New()

	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])

	for jobName, j := range r.GetAllScheduledJobs() {
		if jobName == name {
			fmt.Println(j.Payload.Value)
			return
		}
	}

	fmt.Println("Unit not found.")
	syscall.Exit(1)
}
예제 #9
0
파일: cmd.go 프로젝트: rened/coreinit
func getRegistry(context *cli.Context) *registry.Registry {
	endpoint := context.GlobalString("endpoint")
	client := etcd.NewClient([]string{endpoint})
	return registry.New(client)
}