From df5045e600d7c0fffbb5e0951f43c8e67ad638ce Mon Sep 17 00:00:00 2001
From: Javier Viola <363911+pepoviola@users.noreply.github.com>
Date: Mon, 26 Feb 2024 13:30:01 -0300
Subject: [PATCH] fix(orchestrator): wrapper stderr redirection (#176)

Fix typo :)
---
 .../src/kubernetes/scripts/zombie-wrapper.sh  | 43 ++++++++++++-------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/crates/provider/src/kubernetes/scripts/zombie-wrapper.sh b/crates/provider/src/kubernetes/scripts/zombie-wrapper.sh
index 6b46d87..413a740 100755
--- a/crates/provider/src/kubernetes/scripts/zombie-wrapper.sh
+++ b/crates/provider/src/kubernetes/scripts/zombie-wrapper.sh
@@ -51,20 +51,36 @@ child_pid=""
 # get the command to exec
 CMD=($@)
 
+# File to store CMD (and update from there)
+ZOMBIE_CMD_FILE=/cfg/zombie.cmd
+
+# Store the cmd and make it available to later usage
+# NOTE: echo without new line to allow to customize the cmd later
+$ECHO -n "${CMD[@]}" > $ZOMBIE_CMD_FILE
+
 echo "COMMAND TO RUN IS: $CMD"
 
 start() {
     # redirect the output to be expored to loki
-    "${CMD[@]}" >> /proc/1/fd/1 2 >> /proc/1/fd/2 &
-    child_pid="$!"
-
-    # store pid
-    $ECHO ${child_pid} > /cfg/zombie.pid
-
-    # check if the process is running
-    if ! $LS /proc/$child_pid > /dev/null 2>&1 ; then
-        exit 1
+    "${CMD[@]}" >> /proc/1/fd/1 2>> /proc/1/fd/2 &
+    if [[ "$CMD" != "cat" ]]; then
+        child_pid="$!"
+
+        $ECHO $(cat $ZOMBIE_CMD_FILE)
+        # store pid
+        $ECHO ${child_pid} > /cfg/zombie.pid
+
+        # check if the process is running
+        if ! $LS /proc/$child_pid > /dev/null 2>&1 ; then
+            echo "child process doesn't exist, quiting...";
+            exit 1;
+        else
+            echo "PID: $child_pid alive";
+        fi;
+    else
+        echo "PID not stored, since was 'cat'";
     fi;
+
 }
 
 restart() {
@@ -96,9 +112,9 @@ resume() {
 # keep listening from the pipe
 while read line <$pipe
 do
-    if [[ "$line" == 'start' ]]; then
+    if [[ "$line" == "start" ]]; then
         start
-    elif [[ "$line" == 'quit' ]]; then
+    elif [[ "$line" == "quit" ]]; then
         break
     elif [[ "$line" =~ "restart" ]]; then
         # check if we have timeout between restart
@@ -114,9 +130,4 @@ do
     fi
 done
 
-# exit
-if [ ! -z "${child_pid}" ]; then
-    $KILL -9 "$child_pid"
-fi
-
 exit 0
-- 
GitLab