Переглянути джерело

update job sidecar with global timeout -- more fixes

Alexander Belanger 4 роки тому
батько
коміт
a02f8787f2
1 змінених файлів з 13 додано та 9 видалено
  1. 13 9
      services/job_sidecar_container/job_killer.sh

+ 13 - 9
services/job_sidecar_container/job_killer.sh

@@ -25,18 +25,20 @@ then
   grace_period_seconds=$2
   target=$3
   sidecar=$4
-  global_timeout=$5
 else
   grace_period_seconds=$1
   target=$2
   sidecar=$3
-  global_timeout=$4
 fi  
 
-if [ -n "$global_timeout" ]; then
+global_timeout=$TIMEOUT
+
+if [ -z "$global_timeout" ]; then
   global_timeout=3600
 fi
 
+echo "set global timeout value of $global_timeout"
+
 pattern="$(printf '[%s]%s' $(echo $target | cut -c 1) $(echo $target | cut -c 2-))"
 
 graceful_shutdown() {
@@ -100,18 +102,20 @@ target_pid_name=$(pgrep -f $pattern -l | grep -v 'job_killer.sh' | grep -v 'wait
 if [ -n "$target_pid" ]; then
     echo "targeting pids $target_pid matched by $target_pid_name"
     # schedule hard kill after global timeout
-    (sleep ${timeout}; graceful_shutdown $grace_period_seconds $target || true) &
-    local killer=${!}
+    is_global_shutdown=""
+    (sleep ${global_timeout}; echo "triggering global shutdown" && is_global_shutdown="true" && graceful_shutdown $grace_period_seconds $target || true) &
+    global_killer=${!}
     
     tail --pid=$target_pid -f /dev/null &
     child=$!
 
     wait "$child"
 
-    # cancel hard kill timer
-    sleep 0.1 && kill -9 ${killer} 2>/dev/null || true
-
-    graceful_shutdown $grace_period_seconds $target
+    if [ -z "$is_global_shutdown" ]; then
+      # cancel hard kill timer
+      sleep 0.1 && kill -9 ${global_killer} 2>/dev/null || true
+      graceful_shutdown $grace_period_seconds $target
+    fi
 else 
   echo "no process could be targeted within 10s, initiating shutdown"