Пример #1
0
func Rpc() (*rpc.Client, error) {
	if socketRpc == nil {
		socket := termite.FindSocket()
		if socket == "" {
			wd, _ := os.Getwd()
			return nil, fmt.Errorf("Could not find .termite-socket; cwd: %s", wd)
		}
		topDir, _ = filepath.Split(socket)
		topDir = filepath.Clean(topDir)
		conn := termite.OpenSocketConnection(socket, termite.RPC_CHANNEL, _TIMEOUT)
		socketRpc = rpc.NewClient(conn)
	}
	return socketRpc, nil
}
Пример #2
0
func Refresh() {
	socket := termite.FindSocket()
	conn := termite.OpenSocketConnection(socket, termite.RPC_CHANNEL)

	client := rpc.NewClient(conn)

	req := 1
	rep := 1
	err := client.Call("LocalMaster.RefreshAttributeCache", &req, &rep)
	if err != nil {
		log.Fatal("LocalMaster.RefreshAttributeCache: ", err)
	}
	conn.Close()
}
Пример #3
0
func main() {
	command := flag.String("c", "", "command to run.")
	refresh := flag.Bool("refresh", false, "refresh master file cache.")
	debug := flag.Bool("dbg", false, "set on debugging in request.")
	flag.Parse()

	if *refresh {
		Refresh()
	}

	if *command == "" {
		return
	}
	os.Args[0] = _SHELL
	TryRunDirect(*command)

	socket := termite.FindSocket()
	if socket == "" {
		log.Fatal("Could not find .termite-socket")
	}
	topDir, _ := filepath.Split(socket)

	localWaitMsg, localRule := TryRunLocally(*command, topDir)
	if localWaitMsg != nil && !localRule.SkipRefresh {
		Refresh()
	}

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

	conn := termite.OpenSocketConnection(socket, termite.RPC_CHANNEL)

	// TODO - could skip the shell if we can deduce it is a
	// no-frills command invocation.
	req := termite.WorkRequest{
		Binary:     _SHELL,
		Argv:       []string{"/bin/sh", "-c", *command},
		Env:        cleanEnv(os.Environ()),
		Dir:        wd,
		Debug:      os.Getenv("TERMITE_DEBUG") != "" || *debug,
		RanLocally: localWaitMsg != nil,
	}
	client := rpc.NewClient(conn)

	rep := termite.WorkReply{}
	err = client.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))

	// TODO -something with signals.
	if localWaitMsg == nil {
		localWaitMsg = &rep.Exit
	}
	conn.Close()
	os.Exit(localWaitMsg.ExitStatus())
}