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
#1579)

* feat(orchestrator): store cmd as file and add fn to read and update cmd to execute by wrapper [k8s]

* typo

* nix hash
  • Loading branch information
pepoviola authored Dec 4, 2023
1 parent f94ac0e commit 4f39224
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
...
}: let
# this change on each change of dependencies, unfortunately this hash not yet automatically updated from SRI of package.lock
npmDepsHash = "sha256-crUfrJrTjkKpt2AUL8/E1pa4XoZZorme3ZZocccs2bM=";
npmDepsHash = "sha256-DI22Ywb0ZWIZAnfjqpkGbA0T0g3MbsvdtoI1OeeXLjQ=";
####

# there is officia polkadot on nixpkgs, but it has no local rococo wasm to run
Expand Down
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 reading /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 4f39224

Please sign in to comment.