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

singlestart.sh/reaper now handles SIGCHLD (and better)

parent 0beb18ec
No related branches found
No related tags found
No related merge requests found
......@@ -9,22 +9,34 @@ bootnodekeyfile=${BFANETWORKDIR}/bootnode/key
# Bail out if anything fails.
trap "exit 1" ERR
trap "reaper" SIGINT
# Detect children dying
trap "reaper" SIGINT SIGCHLD
unset LOGDIR LOGPIPE PIDIDX
declare -A PIDIDX
function reaper()
{
local rc
local wecare=0
for pid in ${!PIDIDX[*]}
do
kill -0 $pid 2>/dev/null && continue
rc=wait $pid
local rc=0
wait $pid || rc=$? || true
echo "*** ${PIDIDX[$pid]} (pid $pid) has exited with value $rc"
unset PIDIDX[$pid]
wecare=1
done
test $wecare = 1 || return
# kill all - an extra kill doesn't hurt. I hope.
kill ${!PIDIDX[*]} 2>/dev/null || true
for pid in ${!PIDIDX[*]}
do
# don't kill log.sh, because it may still be logging for us
if [ "${PIDIDX[$pid]}" != "log.sh" ]
then
echo "*** Killing ${PIDIDX[$pid]} (pid $pid)."
kill $pid || true
fi
done
max=30
}
......@@ -73,27 +85,34 @@ LOGPIPE=${LOGDIR}/logpipe
mknod ${LOGPIPE} p
${BFAHOME}/bin/log.sh ${BFANODEDIR}/log < ${LOGPIPE} &
PIDIDX[$!]="log.sh"
exec > ${LOGPIPE} 2>&1
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 &
PIDIDX[$!]="geth"
# bootnode
if [ -r "$bootnodekeyfile" ]
then
echo "*** Starting bootnode."
bootnode --nodekey $bootnodekeyfile > ${LOGPIPE} 2>&1 &
bootnode --nodekey $bootnodekeyfile &
PIDIDX[$!]="bootnode"
fi
echo "*** Starting monitor.js"
monitor.js > ${LOGPIPE} 2>&1 &
monitor.js &
PIDIDX[$!]="monitor.js"
max=-1
while [ -n "${!PIDIDX[*]}" -a $max -ne 0 ]
# Exit if only 1 process remains - we hope it is log.sh, but either way,
# it is time to end.
while [ "${#PIDIDX[*]}" -gt 1 -a $max -ne 0 ]
do
sleep 1
max=$(( $max - 1 ))
done
kill -KILL ${!PIDIDX[*]} 2>/dev/null || true
if [ ${#PIDIDX[*]} -gt 0 ]
then
echo "*** Killing all remaining processes: ${PIDIDX[*]} (${!PIDIDX[*]})."
kill -KILL ${!PIDIDX[*]} 2>/dev/null || true
fi
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