Skip to content

Commit

Permalink
feat(orchestrator): store cmd as file and add fn to read and update c…
Browse files Browse the repository at this point in the history
…md to execute by wrapper [k8s]
  • Loading branch information
pepoviola committed Dec 4, 2023
1 parent 880a556 commit e4e5566
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion javascript/packages/orchestrator/zombie-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ 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"
MKNOD="mknod"
LS="ls"
KILL="kill"
SLEEP="sleep"
CAT="cat"
fi


Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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="$!"
Expand All @@ -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
Expand All @@ -96,6 +111,8 @@ do
pause
elif [[ "$line" == "resume" ]]; then
resume
elif [[ "$line" == "update-cmd" ]]; then
update_zombie_cmd
fi
done

Expand Down

0 comments on commit e4e5566

Please sign in to comment.