Exemple #1
0
func list(level int, prefix string, anchor client.Anchor, recurse bool) {
	if anchor == nil {
		return
	}
	//println(fmt.Sprintf("prefix=%v a=%v/%T r=%v", prefix, anchor, anchor, recurse))
	var c children
	for n, a := range anchor.View() {
		e := &entry{n: n, a: a}
		v := a.Get()
		switch v.(type) {
		case client.Chan:
			e.k = "chan"
		case client.Proc:
			e.k = "proc"
		default:
			if level == 0 {
				e.k = "----"
			}
		}
		c = append(c, e)
	}
	sort.Sort(c)
	for _, e := range c {
		if e.k != "" {
			fmt.Printf("%4s %s%s\n", e.k, prefix, e.n)
		}
		if recurse {
			list(level+1, prefix+e.n+"/", e.a, true)
		}
	}
}
Exemple #2
0
func startNodejs(host client.Anchor, mysqlIP, mysqlPort string) (ip, port string) {
	defer func() {
		if recover() != nil {
			fatalf("connection to host lost")
		}
	}()

	// Start node.js application
	ip = getUbuntuHostPublicIP(host)
	port = "8080"
	job := host.Walk([]string{"nodejs"})
	shell := fmt.Sprintf(
		"sudo /usr/bin/nodejs index.js "+
			"--mysql_host %s --mysql_port %s --api_host %s --api_port %s "+
			"&> /tmp/tutorial-nodejs.log",
		mysqlIP, mysqlPort,
		"0.0.0.0", port,
	)
	proc, err := job.MakeProc(client.Cmd{
		Path:  "/bin/sh",
		Dir:   "/home/ubuntu/nodejs",
		Args:  []string{"-c", shell},
		Scrub: true,
	})
	if err != nil {
		fatalf("nodejs app already running")
	}
	proc.Stdin().Close()
	proc.Stdout().Close()
	proc.Stderr().Close()

	return
}
Exemple #3
0
func list(level int, prefix string, anchor client.Anchor, recurse, long, depth bool) {
	if anchor == nil {
		return
	}
	// println(fmt.Sprintf("prefix=%v a=%v/%T r=%v", prefix, anchor, anchor, recurse))
	var c children
	for n, a := range anchor.View() {
		e := &entry{n: n, a: a}
		v := a.Get()
		switch t := v.(type) {
		case client.Server:
			e.k = "server"
		case client.Chan:
			e.k = "chan"
		case client.Proc:
			e.k = "proc"
			// if t.GetCmd().Scrub {
			// 	e.k = "proc-autoscrub"
			// } else {
			// 	e.k = "proc"
			// }
		case client.Nameserver:
			e.k = "dns"
		case docker.Container:
			e.k = "docker"
		case client.Subscription:
			e.k = "@" + t.Peek().Source
		default:
			e.k = "·"
		}
		c = append(c, e)
	}
	sort.Sort(c)
	for _, e := range c {
		if recurse && depth {
			list(level+1, prefix+e.n+"/", e.a, true, long, depth)
		}
		if long {
			fmt.Printf("%-15s %s%s\n", e.k, prefix, e.n)
		} else {
			fmt.Printf("%s%s\n", prefix, e.n)
		}
		if recurse && !depth {
			list(level+1, prefix+e.n+"/", e.a, true, long, depth)
		}
	}
}
Exemple #4
0
func runShellStdin(host client.Anchor, cmd, stdin string) (string, error) {
	defer func() {
		if recover() != nil {
			fatalf("connection to host lost")
		}
	}()
	job := host.Walk([]string{"shelljob", strconv.Itoa(rand.Int())})
	proc, _ := job.MakeProc(client.Cmd{
		Path:  "/bin/sh",
		Dir:   "/tmp",
		Args:  []string{"-c", cmd},
		Scrub: true,
	})
	go func() {
		io.Copy(proc.Stdin(), bytes.NewBufferString(stdin))
		proc.Stdin().Close() // Must close the standard input of the shell process.
	}()
	proc.Stderr().Close() // Close to indicate discarding standard error
	var buf bytes.Buffer
	io.Copy(&buf, proc.Stdout())
	stat, _ := proc.Wait()
	return buf.String(), stat.Exit
}