[ARVADOS] created: 90bea0ac06dc351fa3a1aefc896ad1ab4b0b1dea

Git user git at public.curoverse.com
Thu Dec 15 16:56:38 EST 2016


        at  90bea0ac06dc351fa3a1aefc896ad1ab4b0b1dea (commit)


commit 90bea0ac06dc351fa3a1aefc896ad1ab4b0b1dea
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Dec 15 16:56:18 2016 -0500

    10585: Add crunchstat -signal-on-dead-ppid option.

diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index cae95fd..e7d633f 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -16,6 +16,8 @@ import (
 
 const MaxLogLine = 1 << 14 // Child stderr lines >16KiB will be split
 
+var signalOnDeadPPID int
+
 func main() {
 	reporter := crunchstat.Reporter{
 		Logger: log.New(os.Stderr, "crunchstat: ", 0),
@@ -24,6 +26,7 @@ func main() {
 	flag.StringVar(&reporter.CgroupRoot, "cgroup-root", "", "Root of cgroup tree")
 	flag.StringVar(&reporter.CgroupParent, "cgroup-parent", "", "Name of container parent under cgroup")
 	flag.StringVar(&reporter.CIDFile, "cgroup-cid", "", "Path to container id file")
+	flag.IntVar(&signalOnDeadPPID, "signal-on-dead-ppid", 15, "Signal to send child if crunchstat's parent process disappears")
 	pollMsec := flag.Int64("poll", 1000, "Reporting interval, in milliseconds")
 
 	flag.Parse()
@@ -77,6 +80,31 @@ func runCommand(argv []string, logger *log.Logger) error {
 	signal.Notify(sigChan, syscall.SIGTERM)
 	signal.Notify(sigChan, syscall.SIGINT)
 
+	// Kill our child proc if our parent process disappears
+	go func() {
+		if signalOnDeadPPID == 0 {
+			return
+		}
+		ppidOrig := os.Getppid()
+		for _ = range time.NewTicker(time.Second).C {
+			ppid := os.Getppid()
+			if ppid == ppidOrig {
+				continue
+			}
+			if cmd.Process == nil {
+				// Child process isn't running yet
+				continue
+			}
+			logger.Printf("notice: crunchstat ppid changed from %d to %d -- killing child pid %d with signal %d", ppidOrig, ppid, cmd.Process.Pid, signalOnDeadPPID)
+			err := cmd.Process.Signal(syscall.Signal(signalOnDeadPPID))
+			if err != nil {
+				logger.Printf("error: sending signal: %d", err)
+				continue
+			}
+			break
+		}
+	}()
+
 	// Funnel stderr through our channel
 	stderr_pipe, err := cmd.StderrPipe()
 	if err != nil {

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list