瀏覽代碼

add signal script to job sidecar container

Alexander Belanger 5 年之前
父節點
當前提交
c3775460ef

+ 2 - 2
services/job_sidecar_container/Dockerfile

@@ -3,8 +3,8 @@ FROM alpine:latest
 # fetch procps for ps command, coreutils for tail with -pid flag
 RUN apk --no-cache add procps coreutils
 
-COPY job_killer.sh .
+COPY *.sh .
 
-RUN ["chmod", "+x", "./job_killer.sh"]
+RUN ["chmod", "+x", "./job_killer.sh", "./signal.sh"]
 
 ENTRYPOINT ["./job_killer.sh"]

+ 3 - 4
services/job_sidecar_container/job_killer.sh

@@ -14,11 +14,9 @@
 kill_child_procs=false
 
 while getopts ":c" opt; do
-  echo "OPT IS $opt"
   case $opt in
     c)
       kill_child_procs=true
-      echo "set kill child procs"
   esac
 done
 
@@ -46,12 +44,13 @@ graceful_shutdown() {
     # request graceful shutdown from target_pid
     kill -0 ${target_pid} 2>/dev/null && kill -TERM ${target_pid}
 
-    if $kill_child_procs; do
+    if $kill_child_procs
+    then
         for c in $(ps -o pid= --ppid $target_pid); do
           # request graceful shutdown of all children, and append to process list
           kill -0 $c 2>/dev/null && kill -TERM $c && list="$list $c" || true
         done
-    done
+    fi
 
     if [ -n "$target_pid" ]; then
         # schedule hard kill after timeout

+ 6 - 0
services/job_sidecar_container/signal.sh

@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Sends termination signal to job_killer.sh, which triggers the job shutdown process.
+
+pid=$(ps x | grep "[.]/job_killer.sh" | awk '{ printf "%d ", $1 }'); 
+kill -TERM $pid