示例#1
0
文件: start.go 项目: jweslley/procker
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...)
}
示例#2
0
文件: start.go 项目: jweslley/procker
func start(args []string) {
	processes := parseProfile(*startProcfile)
	env := parseEnv(*startEnvfile)
	dir := path.Dir(*startProcfile)
	padding := longestName(processes)
	log.SetFlags(0)
	log.SetOutput(procker.NewPrefixedWriter(os.Stdout, prefix(programName, padding)))
	process := buildProcess(args, processes, dir, env, *startBasePort, padding)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		stopping := false
		for sig := range c {
			if stopping {
				log.Printf("%v signal received, killing processes and exiting.", sig)
				process.Signal(syscall.SIGKILL)
			} else {
				log.Printf("%v signal received, stopping processes and exiting.", sig)
				stopping = true
				go func() {
					process.Stop(time.Duration(*startStopTimeout) * time.Second)
				}()
			}
		}
	}()

	err := process.Start()
	failIf(err)

	process.Wait()
}
示例#3
0
文件: apps.go 项目: 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
}