Exemplo n.º 1
0
func runCommand(cmd, arg string) {
	var client gonit.CliClient

	if settings.Daemon.IsRunning() {
		rpc := rpcClient()
		defer rpc.Close()
		client = gonit.NewRemoteClient(rpc, api)
	} else {
		client = gonit.NewLocalClient(api)
	}

	method, name := gonit.RpcArgs(cmd, arg, group)

	reply, err := client.Call(method, name)

	if err != nil {
		log.Fatal(err)
	}

	if formatter, ok := reply.(gonit.CliFormatter); ok {
		formatter.Print(os.Stdout)
	} else {
		log.Printf("%#v", reply) // TODO make perty
	}
}
Exemplo n.º 2
0
func (r *AdminRpcs) UnInit() {
	for _, rpc := range r.adminRpc {
		rpc.Close()
	}
	for _, m := range r.CHash.Members() {
		r.CHash.Remove(m)
	}
	r.adminRpc = nil
}
Exemplo n.º 3
0
func (r *PushRpcs) UpdateConfig() {
	var err error
	config := Conf.Server.RpcPush
	pushrpc := make([]*PushRpc, 0)
	for _, node := range config {
		rpc := NewPushRpc()
		if err = rpc.Init(node); err != nil {
			continue
		} else {
			pushrpc = append(pushrpc, rpc)
		}
	}
	if err == nil && len(pushrpc) != 0 {
		for _, rpc := range r.pushRpc {
			rpc.Close()
		}
		r.Config = config
		r.pushRpc = pushrpc
	} else {
		log.Fatalf("push rpc update config failed")
	}
}
Exemplo n.º 4
0
func main() {
	command := flag.String("c", "", "command to run.")
	refresh := flag.Bool("refresh", false, "refresh master file cache.")
	shutdown := flag.Bool("shutdown", false, "shutdown master.")
	inspect := flag.Bool("inspect", false, "inspect files on master.")
	exec := flag.Bool("exec", false, "run command args without shell.")
	directory := flag.String("dir", "", "directory from where to run (default: cwd).")
	worker := flag.String("worker", "", "request to run on a worker explicitly")
	debug := flag.Bool("dbg", false, "set on debugging in request.")

	flag.Parse()
	log.SetPrefix("S")

	if *shutdown {
		req := 1
		rep := 1
		rpc, err := Rpc()
		err = rpc.Call("LocalMaster.Shutdown", &req, &rep)
		if err != nil {
			log.Fatal(err)
		}
		return
	}
	if *refresh {
		Refresh()
	}

	if *inspect {
		Inspect(flag.Args())
	}

	if *directory == "" {
		wd, err := os.Getwd()
		if err != nil {
			log.Fatal("Getwd", err)
		}

		directory = &wd
	}

	var req *termite.WorkRequest
	var rule *termite.LocalRule
	if *exec {
		req = &termite.WorkRequest{
			Binary: flag.Args()[0],
			Argv:   flag.Args(),
			Dir:    *directory,
			Env:    os.Environ(),
		}
	} else {
		req, rule = PrepareRun(*command, *directory, topDir)
	}
	var waitMsg syscall.WaitStatus
	rep := termite.WorkResponse{}
	if rule != nil && rule.Local {
		waitMsg = RunLocally(req, rule)
		if !rule.SkipRefresh {
			Refresh()
		}
		rep.WorkerId = "(local)"
	} else {
		req.Debug = req.Debug || os.Getenv("TERMITE_DEBUG") != "" || *debug
		req.Worker = *worker

		req.TrackReads = true
		req.DeclaredDeps = strings.Split(os.Getenv("MAKE_DEPS"), " ")
		req.DeclaredTarget = os.Getenv("MAKE_TARGET")

		rpc, err := Rpc()
		if err != nil {
			log.Fatalf("rpc connection problem (%s): %v", *command, err)
		}

		err = rpc.Call("LocalMaster.Run", req, &rep)
		if err != nil {
			log.Fatal("LocalMaster.Run: ", err)
		}

		os.Stdout.Write([]byte(rep.Stdout))
		os.Stderr.Write([]byte(rep.Stderr))

		waitMsg = rep.Exit
	}

	if waitMsg != 0 {
		log.Printf("Failed %s: '%q'", rep.WorkerId, *command)
	}

	// TODO - is this necessary?
	rpc, _ := Rpc()
	rpc.Close()
	os.Exit(int(waitMsg))
}