Skip to content

Commit

Permalink
sysproc attr args to ensure sigint does not get passed to child proce…
Browse files Browse the repository at this point in the history
…sses
  • Loading branch information
neel-bp committed Apr 4, 2023
1 parent 29f2f66 commit e2dc85d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 6 additions & 1 deletion core/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"sync"
"syscall"
"time"

"ghhooks.com/hook/jobqueue"
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -71,7 +71,6 @@ func main() {
}

<-httpServerCloseChan
core.Queues.DrainAll()
wg.Wait()

fmt.Println("done")
Expand Down

0 comments on commit e2dc85d

Please sign in to comment.