diff --git a/core/job.go b/core/job.go index d2228e7..48ce584 100644 --- a/core/job.go +++ b/core/job.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "sync" + "syscall" "time" "ghhooks.com/hook/jobqueue" @@ -106,6 +107,10 @@ func Job(args ...any) error { ctx, cancel := context.WithTimeout(Ctx, duration) cmd := exec.CommandContext(ctx, command, args...) cmd.Dir = project.Cwd + // to ensure the sigint sigterm does not get passed to child processes, + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + } out, err := cmd.Output() cancel() @@ -185,7 +190,7 @@ func ServerInit(configlocation string, l *log.Logger, wg *sync.WaitGroup) error } ServerConf = conf Queues = make(jobqueue.QueueMap, 0) - for projectName, _ := range ServerConf.Project { + for projectName := range ServerConf.Project { jg := jobqueue.NewJobQueue(projectName, make(chan jobqueue.Job, 25), 1) err = Queues.Register(jg) if err != nil { diff --git a/example.toml b/example.toml index 12e0d39..3104f98 100644 --- a/example.toml +++ b/example.toml @@ -2,12 +2,12 @@ branch = "master" secret = "xxx" -cwd = 'c:\games' +cwd = '/home/neelu/experiments' steps = [ - ["goprint.exe","start"], - ["gosleep.exe","2"], - ["goprint.exe","mid"], - ["gosleep.exe","3"], - ["goprint.exe","end"] + ["echo","start"], + ["sleep","2"], + ["echo","mid"], + ["sleep","10"], + ["echo","end"] ] stepTimeout = 600 \ No newline at end of file diff --git a/main.go b/main.go index 928de19..46ec563 100644 --- a/main.go +++ b/main.go @@ -57,8 +57,8 @@ func main() { sigc := make(chan os.Signal, 1) signal.Notify(sigc, os.Interrupt) <-sigc - fmt.Println("gracefully shutting down") - // core.Queues.DrainAll() + fmt.Printf("\ngracefully shutting down\n") + core.Queues.DrainAll() if err := srv.Shutdown(context.Background()); err != nil { l.Printf("HTTP server shurdown error: %v\n", err) @@ -71,7 +71,6 @@ func main() { } <-httpServerCloseChan - core.Queues.DrainAll() wg.Wait() fmt.Println("done")