I gotcha. So what does you’re after.sh.erb
look like now? If I were update our jupyter after.sh.erb, here’s what it’d look like.
This wraps the wait_until_port_used into a retry while loop so that it’ll only wait_until_port_used if the pid is actually running. So it’ll give you sleep time * retires seconds (3*10, 30 seconds) to start-up before entering the wait_until_port_used.
retries=0
while [ $retries -lt 10 ]
do
if ps ${script_pid} >/dev/null 2>&1; then
echo "Waiting for Jupyter server to open port ${port}..."
if wait_until_port_used "${host}:${port}" 600; then
echo "Discovered Jupyter server listening on port ${port}!"
else
echo "Timed out waiting for Jupyter server to open port ${port}!"
clean_up 1
fi
else
echo "script pid $script_pid doesn't exist. retrying."
retires=$((retries+1))
sleep 3
fi
done
if retires -ge 10; then
echo "${script_pid} never came up after ${retries}"
clean_up 1
fi
another variation may be something like:
function ps_up_and_port_used(){
local script_pid=$1
local host=$2
local port=$3
if ps ${script_pid} >/dev/null 2>&1; then
if wait_until_port_used "${host}:${port}" 30;
return 0
else
return 1
fi
else
return 1
fi
}
retries=0
while [ $retries -lt 10 ]
do
if ps_up_and_port_used $script_pid $host $port; then
echo "Discovered Jupyter server listening on port ${port}!"
else
echo "either pid $script_pid doesn't exist or $port not yet open. retrying."
retires=$((retries+1))
sleep 3
fi
done
if retires -ge 10; then
echo "${script_pid} never came up after ${retries}"
clean_up 1
fi