Ejemplo n.º 1
0
func buildProcess(
	processNames []string,
	processes map[string]string,
	dir string,
	env []string,
	port, padding int) procker.Process {

	p := []procker.Process{}
	for name, command := range processes {
		if !mustStart(processNames, name) {
			continue
		}

		process := &procker.SysProcess{
			Command:     command,
			Dir:         dir,
			Env:         append(env, fmt.Sprintf("PORT=%d", port)),
			Stdout:      procker.NewPrefixedWriter(os.Stdout, prefix(name, padding)),
			Stderr:      procker.NewPrefixedWriter(os.Stderr, prefix(name, padding)),
			SysProcAttr: sysProcAttrs(),
		}

		log.Printf("starting %s on port %d", name, port)
		p = append(p, process)
		port++
	}

	if len(p) == 0 {
		fail("no process to run\n")
	}

	return procker.NewProcessGroup(p...)
}
Ejemplo n.º 2
0
Archivo: apps.go Proyecto: nwlucas/bam
func (a *processApp) buildProcess() (procker.Process, error) {
	port, err := FreePort()
	if err != nil {
		return nil, err
	}

	a.port = port
	p := []procker.Process{}
	for name, command := range a.processes {
		prefix := fmt.Sprintf("[%s:%s] ", a.Name(), name)
		process := &procker.SysProcess{
			Command: command,
			Dir:     a.dir,
			Env:     append(a.env, fmt.Sprintf("PORT=%d", port)),
			Stdout:  procker.NewPrefixedWriter(os.Stdout, prefix),
			Stderr:  procker.NewPrefixedWriter(os.Stderr, prefix),
		}
		p = append(p, process)
	}
	return procker.NewProcessGroup(p...), nil
}