Skip to content

Commit

Permalink
Fix signal handling in TUI mode and add SIGHUP (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Jan 7, 2023
1 parent 70e16ea commit 68a5103
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/cmd/project_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,29 @@ func runProject(isDefConfigPath bool, process []string, noDeps bool) {
os.Exit(exitCode)
}

func runHeadless(project *app.Project) int {
func setSignal(signalHandler func()) {
cancelChan := make(chan os.Signal, 1)
// catch SIGTERM or SIGINTERRUPT
signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT)

signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
go func() {
sig := <-cancelChan
log.Info().Msgf("Caught %v - Shutting down the running processes...", sig)
project.ShutDownProject()
signalHandler()
os.Exit(1)
}()
}

func runHeadless(project *app.Project) int {
setSignal(func() {
project.ShutDownProject()
})
exitCode := project.Run()
return exitCode
}

func runTui(project *app.Project) int {
setSignal(func() {
tui.Stop()
})
defer quiet()()
go tui.SetupTui(project.LogLength)
exitCode := project.Run()
Expand Down

0 comments on commit 68a5103

Please sign in to comment.