Example #1
0
func StartLeaf(leaf string) *Leaf {
	if entry, ok := GetLeaf(leaf); ok {
		return entry
	}

	secret := common.GenerateSecret()

	log.Printf("Starting %s under port %d", leaf, port)
	command := fmt.Sprintf("%s -- --mode leaf --port %d --secret %s 2>&1", headPath, port, secret)

	prefix := []byte(fmt.Sprintf("[%s] ", leaf))
	output := text.NewIndentWriter(os.Stdout, prefix)

	entry := &Leaf{
		State:  "launching",
		Secret: secret,
		Anchor: exec.Command("enter-chroot", "-n", leaf, "sh", "-c", command),
	}
	entry.Anchor.Stdout = output
	entry.Anchor.Start()

	go func() {
		err := entry.Anchor.Wait()
		log.Printf("Leaf %s exited with %+v", leaf, err)

		if err != nil {
			entry.State = "crashed"
		} else {
			entry.State = "stopped"
		}
	}()

	Leaves[leaf] = entry
	return entry
}
Example #2
0
func (p *printer) indent() *printer {
	q := *p
	q.tw = tabwriter.NewWriter(p.Writer, 4, 4, 1, ' ', 0)
	q.Writer = text.NewIndentWriter(q.tw, []byte{'\t'})
	return &q
}