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

Better tools and starting to monitor

parent 1358eac0
No related branches found
No related tags found
No related merge requests found
*/lastseen
*/node*
*/status
#!/bin/bash
trap 'exit 1' ERR
cd `dirname $0`
source ./env
exec < /dev/null > /dev/null 2> /dev/null
(
./start.sh &
while ./monitor.sh
do
sleep 60
done &
)
export BFAHOME=${HOME}/bfa
export BFANETWORKDIR="${BFAHOME}/network5445"
export BFANETWORKID=5445
PATH=${PATH}:${BFAHOME}/bin
......@@ -2,6 +2,7 @@
# 20180626 Robert Martin-Legene <robert@nic.ar>
trap "echo Argh! ; exit 1" ERR
set -e -o errtrace
function fatal()
{
......@@ -54,16 +55,18 @@ function geth_exec_js
function getnetworkid
{
test -n "${BFANETWORKID}" &&
return
local dir="${BFANETWORKDIR}"
for dir in $( ls -1d "${BFAHOME}"/* | sort --version-sort )
do
if [ -d "${dir}" ]
then
local base=$( basename "${dir}" )
base=$( echo "${base}" | grep -E '^network[0-9]+$' )
if [ -n "$base" ]
base=$( echo "${base}" | grep -E '^network[0-9]+$' ) || true
if [ -n "${base:7}" ]
then
BFANETWORKID=${network:7}
BFANETWORKID=${base:7}
return
fi
fi
......@@ -98,8 +101,7 @@ function networkdir
stderr "Consider running: mkdir ${BFAHOME}/network${num} or set BFANETWORKDIR in ${BFAHOME}/bin/env"
exit 1
fi
# Get network id
BFANETWORKID=${BFANETWORKDIR:7}
getnetworkid
}
function nodedir
......@@ -124,9 +126,10 @@ function nodedir
fatal "$BFANODEDIR is not a directory."
test -d "${BFANODEDIR}/geth/chaindata" ||
fatal "Node is not initialised. Consider running: geth --datadir $BFANODEDIR init ${BFANETWORKDIR}/genesis.json"
test -r "${BFANODEDIR}/port" ||
test -r "${BFANODEDIR}/netport" ||
echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/netport
httpport=$( cat ${BFANODEDIR}/netport )
netport=$( cat ${BFANODEDIR}/netport )
test $? = 0
test -r "${BFANODEDIR}/rpcport" ||
echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/rpcport
rpcport=$( cat ${BFANODEDIR}/rpcport )
......@@ -140,7 +143,7 @@ function account
test -d "${BFANODEDIR}/keystore"
account=$( ls -1dl "${BFANODEDIR}"/keystore/*--* | head -1 | sed 's/.*--//' )
fi
if [ -n "$account" ]
if [ -z "$account" ]
then
fatal "No accounts found. Consider running: geth --datadir ${BFANETWORKDIR}/node1 --password /dev/null account new"
fi
......
#!/bin/bash
trap "echo Argh; exit 1" ERR
true ${MAXSIZE:=$((10*1024*1024))}
log=$1
......
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
function json_query
{
cmd=$1
params=$2
if [ -n "$params" ]
then
params=",\"parameters\":[$2]"
fi
json=$(
curl -s -H 'Content-type: application/json' -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" http://127.0.0.1:$rpcport
)
}
function json_err
{
echo "$json" | jq -r '.result'
}
function json_arraylength
{
jq -r length
}
function json_result
{
echo "$json" | jq -r '.result'
}
bfaconfig node
json_query admin_peers
numpeers=$( json_result | json_arraylength )
statusfile=$( bfamktemp )
(
echo -n "time: "
date
echo "total-peer-count: ${numpeers}"
) > $statusfile
peercount=0
for idx in $( seq 0 $(( $numpeers - 1 )) )
do
eth=$( echo "$json" | jq -r .result[$idx].protocols.eth )
if [ "$eth" = "handshake" ]
then
continue
fi
#echo -n "$idx: "; echo "$eth" | jq -c
remoteid=$(
echo "$json" |
jq -r .result[$idx].id
)
remoteip=$(
echo "$json" |
jq -r .result[$idx].network.remoteAddress |
sed 's/:[0-9][0-9]*$//'i
)
mkdir -p "${BFANETWORKDIR}/lastseen/${remoteid}"
touch "${BFANETWORKDIR}/lastseen/${remoteid}/${remoteip}"
echo "peer: ${remoteid}" >> $statusfile
peercount=$(( $peercount + 1 ))
done
echo "valid-peer-count: ${peercount}" >> $statusfile
mv -f $statusfile ${BFANETWORKDIR}/status
......@@ -64,9 +64,13 @@ bootnodeport=5445
bootnodes="enode://${bootnodeid}@[$bootnodev6]:${bootnodeport},enode://${bootnodeid}@[$bootnodev4]:${bootnodeport}"
bfaconfig max
set -x
# Start the miner.
exec flock --nonblock --exclusive ${BFANODEDIR}/rpcport \
(
echo
echo '***'
echo
set -x
# Start the miner.
exec flock --nonblock --exclusive ${BFANODEDIR}/rpcport \
geth \
--datadir ${BFANODEDIR} \
--unlock "$account" \
......@@ -75,8 +79,13 @@ exec flock --nonblock --exclusive ${BFANODEDIR}/rpcport \
--networkid $BFANETWORKID \
--rpc \
--rpcport $rpcport \
--rpcapi "eth,net,web3,admin,clique,miner" \
--port $netport \
--syncmode full \
--nousb \
--bootnodes "${bootnodes}" \
--gcmode archive \
--cache 512 \
--verbosity 3
) 2>&1 |
${BFAHOME}/bin/log.sh ${BFANODEDIR}/log
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