Skip to content
Snippets Groups Projects
Commit af2c7fb7 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Fate-sharing process control

parent c1cd5d6b
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,20 @@ bootnodekeyfile=${BFANETWORKDIR}/bootnode/key ...@@ -9,6 +9,20 @@ bootnodekeyfile=${BFANETWORKDIR}/bootnode/key
# Bail out if anything fails. # Bail out if anything fails.
trap "exit 1" ERR trap "exit 1" ERR
unset LOGDIR LOGPIPE PIDIDX
declare -A PIDIDX
function reaper()
{
local rc
for pid in ${!PIDIDX[*]}
do
kill -0 $pid 2>/dev/null && continue
rc=wait $pid
echo "${PIDIDX[$pid]} (pid $pid) has exited with value $rc"
unset aaa[$pid]
done
}
if [ "$VIRTUALIZATION" = "DOCKER" ] if [ "$VIRTUALIZATION" = "DOCKER" ]
then then
...@@ -47,35 +61,40 @@ then ...@@ -47,35 +61,40 @@ then
echo "or: docker exec -i bfanode bfalog.sh" echo "or: docker exec -i bfanode bfalog.sh"
fi fi
unset LOGDIR LOGPIPE PIDLIST
echo "*** Setting up logging." echo "*** Setting up logging."
# Clean up logging # Clean up logging
LOGDIR=$( mktemp -d ) LOGDIR=$( mktemp -d )
trap "rm -f ${LOGDIR}" EXIT trap "rm -rf ${LOGDIR}" EXIT
LOGPIPE=${LOGDIR}/logpipe LOGPIPE=${LOGDIR}/logpipe
mknod ${LOGPIPE} p mknod ${LOGPIPE} p
${BFAHOME}/bin/log.sh ${BFANODEDIR}/log < ${LOGPIPE} & ${BFAHOME}/bin/log.sh ${BFANODEDIR}/log < ${LOGPIPE} &
PIDLIST="${PIDLIST} $!" PIDIDX[$!]="log.sh"
echo "*** Starting geth." echo "*** Starting geth."
geth --config ${BFATOML} --gcmode archive --verbosity ${BFAVERBOSITY:-3} --allow-insecure-unlock > ${LOGPIPE} 2>&1 & geth --config ${BFATOML} --gcmode archive --verbosity ${BFAVERBOSITY:-3} --allow-insecure-unlock > ${LOGPIPE} 2>&1 &
PIDLIST="${PIDLIST} $!" PIDIDX[$!]="geth"
# bootnode # bootnode
if [ -r "$bootnodekeyfile" ] if [ -r "$bootnodekeyfile" ]
then then
echo "*** Starting bootnode." echo "*** Starting bootnode."
bootnode --nodekey $bootnodekeyfile & bootnode --nodekey $bootnodekeyfile > ${LOGPIPE} 2>&1 &
PIDLIST="${PIDLIST} $!" PIDIDX[$!]="bootnode"
fi fi
echo "*** Starting monitor.js" echo "*** Starting monitor.js"
monitor.js & monitor.js > ${LOGPIPE} 2>&1 &
PIDLIST="${PIDLIST} $!" PIDIDX[$!]="monitor.js"
wait -n # if one dies wait -n # if one dies
echo "*** Some process ended, so will shut down other processes too." > ${LOGPIPE}
sleep 2 # give log.sh time to work on the data written, before we kill it. sleep 2 # give log.sh time to work on the data written, before we kill it.
kill ${PIDLIST} # kill all echo "*** Some process ended, so will shut down other processes too." > ${LOGPIPE}
wait # wait for them all to end kill ${!PIDIDX[*]} 2>/dev/null || true # kill all
# wait for them all to end
max=30
while [ -n "${!PIDIDX[*]}" -a $max -gt 0 ]
do
sleep 1
max=$(( $max - 1 ))
done
kill -KILL ${!PIDIDX[*]} 2>/dev/null || true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment