]> Cypherpunks.ru repositories - goredo.git/blobdiff - main.go
Kill children
[goredo.git] / main.go
diff --git a/main.go b/main.go
index 67c428c14a6b6661bdc9bf94ae4dac0a0cf1062b..c3b1be78677b731291db45ca8af4cfab7b74a5d3 100644 (file)
--- a/main.go
+++ b/main.go
@@ -27,11 +27,13 @@ import (
        "io/ioutil"
        "log"
        "os"
+       "os/signal"
        "path"
        "path/filepath"
        "runtime"
        "sort"
        "strconv"
+       "syscall"
 
        "go.cypherpunks.ru/recfile"
        "golang.org/x/sys/unix"
@@ -282,6 +284,20 @@ func main() {
                }
        }
 
+       killed := make(chan os.Signal, 0)
+       signal.Notify(killed, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
+       go func() {
+               <-killed
+               trace(CDebug, "[%s] killed", BuildUUID)
+               jsReleaseAll()
+               RunningProcsM.Lock()
+               for pid, proc := range RunningProcs {
+                       trace(CDebug, "[%s] killing child %d", BuildUUID, pid)
+                       proc.Signal(syscall.SIGTERM)
+               }
+               os.Exit(1)
+       }()
+
        ok := true
        err = nil
        trace(