From e4e55665f849f0df389ed3b775b1bba2399da63d Mon Sep 17 00:00:00 2001 From: Javier Viola Date: Mon, 4 Dec 2023 18:21:07 -0300 Subject: [PATCH] feat(orchestrator): store cmd as file and add fn to read and update cmd to execute by wrapper [k8s] --- .../packages/orchestrator/zombie-wrapper.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/javascript/packages/orchestrator/zombie-wrapper.sh b/javascript/packages/orchestrator/zombie-wrapper.sh index a9f179eb3..1a9ff56df 100755 --- a/javascript/packages/orchestrator/zombie-wrapper.sh +++ b/javascript/packages/orchestrator/zombie-wrapper.sh @@ -8,6 +8,8 @@ if [ -f /cfg/coreutils ]; then LS="/cfg/coreutils ls" KILL="/cfg/coreutils kill" SLEEP="/cfg/coreutils sleep" + ECHO="/cfg/coreutils echo" + CAT="/cfg/coreutils cat" else RM="rm" MKFIFO="mkfifo" @@ -15,6 +17,7 @@ else LS="ls" KILL="kill" SLEEP="sleep" + CAT="cat" fi @@ -44,6 +47,8 @@ child_pid="" # get the command to exec CMD=($@) +# File to store CMD (and update from there) +ZOMBIE_CMD_FILE=/cfg/zombie.cmd restart() { if [ ! -z "${child_pid}" ]; then $KILL -9 "$child_pid" @@ -71,6 +76,16 @@ resume() { fi } +# update start cmd by readin /cfg/zombie.cmd +update_zombie_cmd() { + NEW_CMD=$($CAT $ZOMBIE_CMD_FILE) + CMD=($NEW_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 + # Exec the command and get the child pid "${CMD[@]}" & child_pid="$!" @@ -83,7 +98,7 @@ fi; # keep listening from the pipe while read line <$pipe do - if [[ "$line" == 'quit' ]]; then + if [[ "$line" == "quit" ]]; then break elif [[ "$line" =~ "restart" ]]; then # check if we have timeout between restart @@ -96,6 +111,8 @@ do pause elif [[ "$line" == "resume" ]]; then resume + elif [[ "$line" == "update-cmd" ]]; then + update_zombie_cmd fi done