// Run retrieves task information from etcd and executes it.
Run retrieves task information from etcd and executes it.
// Run retrieves task information from etcd and executes it .
func (h *shellHandler) Run() (done bool) {
	const sort, recurs = false, false
	if len(h.task.Args) == 0 {
		h.log("No Args in task")
		return true
	}
	cmd := exec.Command(h.task.Args[0], h.task.Args[1:]...)
	stdout, stderr, err := outFiles(h.task.ID())
	if err != nil {
		h.log("Could not create log files: %v", err)
		return false
	}
	defer stdout.Close()
	defer stderr.Close()
	cmd.Stdout = stdout
	cmd.Stderr = stderr
	h.m.Lock()
	if h.stop {
		h.log("Task stopped before it even started.")
		h.m.Unlock()
		return false
	}
	h.log("Running task: %s", strings.Join(h.task.Args, " "))
	if err := cmd.Start(); err != nil {
		h.m.Unlock()
		h.log("Error starting task: %v", err)
		return true
	}
	h.p = cmd.Process
	h.ps = cmd.ProcessState
	h.m.Unlock()
	h.log("running")
	if err := cmd.Wait(); err != nil {
		if err.(*exec.ExitError).Sys().(syscall.WaitStatus).Signal() == os.Interrupt {
			h.log("Stopping")
			done = false
		} else {
			h.log("Exited with error: %v", err)
			done = true 
		}
	} else {
		done = true
	}
	h.log("done? %t", done)
	return done
}
func ( h * shellHandler ) Run ( ) ( done bool ) { const sort , recurs = false , false if len ( h . task . Args ) == 0 { h . log ( " " ) return true } cmd := exec . Command ( h . task . Args [ 0 ] , h . task . Args [ 1 : ] ... ) stdout , stderr , err := outFiles ( h . task . ID ( ) ) if err != nil { h . log ( " " , err ) return false } defer stdout . Close ( ) defer stderr . Close ( ) cmd . Stdout = stdout cmd . Stderr = stderr h . m . Lock ( ) if h . stop { h . log ( " " ) h . m . Unlock ( ) return false } h . log ( " " , strings . Join ( h . task . Args , " " ) ) if err := cmd . Start ( ) ; err != nil { h . m . Unlock ( ) h . log ( " " , err ) return true } h . p = cmd . Process h . ps = cmd . ProcessState h . m . Unlock ( ) h . log ( " " ) if err := cmd . Wait ( ) ; err != nil { if err . ( * exec . ExitError ) . Sys ( ) . ( syscall . WaitStatus ) . Signal ( ) == os . Interrupt { h . log ( " " ) done = false } else { h . log ( " " , err ) done = true } } else { done = true } h . log ( " " , done ) return done }
Run retrieves task information from etcd and executes it.
Run retrieves task information from etcd and executes it .
// Set stdout and stderr to temporary files // Entering critical section where we have to lock handler fields to avoid // race conditions with Stop() getting called. // Leaving critical section. Now if Stop() is called, cmd.Wait() will return. // Not done! // don't retry commands that error'd