Ejemplo n.º 1
0
func runProgram(p *program.Program, stopChan chan struct{}) {
	cmd, err := p.GetCmd()
	if err != nil {
		return
	}
	fmt.Printf("Name: %s, Config: %+v\n", p.Name, cmd)
	err = cmd.Start()
	if err != nil {
		return
	}
	done := make(chan error, 1)
	go func() {
		done <- cmd.Wait()
	}()
	select {
	case <-stopChan:
		if err := cmd.Process.Kill(); err != nil {
			log.Fatal("failed to kill: ", err)
		}
		<-done // allow goroutine to exit
		log.Println("process killed")
	case err := <-done:
		if err != nil {
			log.Printf("process done with error = %v", err)
		}
	}
}
Ejemplo n.º 2
0
func parseProgramLine(line string, program *program.Program) error {
	key, value, err := getKeyVal(line)
	if err != nil {
		return err
	}

	if key == "command" {
		program.Command = value
	}
	if key == "directory" {
		program.Directory = value
	}
	if key == "priority" {
		program.Priority, err = strconv.ParseInt(value, 10, 64)
	}
	return err
}
Ejemplo n.º 3
0
func (c *Config) addProgram(p *program.Program) {
	if p != nil && p.IsValid() {
		c.Programs[p.Name] = p
	}
}