nimbus-eth1-blobs/scripts/run-beacon-session.sh

344 lines
7.8 KiB
Bash
Raw Normal View History

#! /bin/sh
2022-03-25 10:57:34 +00:00
self=${BEACON_SESSION_SELF:-`basename "$0"`}
# Network name (used below for easy setup)
2022-03-25 10:57:34 +00:00
name=${BEACON_SESSION_NAME:-kiln}
2022-05-10 08:44:37 +00:00
fullname=${BEACON_SESSION_FULLNAME:-$name}
2022-03-25 10:57:34 +00:00
# Digits, instance id appended to directory name
instance=${BEACON_SESSION_INSTANCE:-0}
2022-03-25 10:57:34 +00:00
# Unique beacon TCP/UDP communication port => tcp_port + instance
base_tcpport=${BEACON_SESSION_TCP_PORT:-9000}
base_udpport=${BEACON_SESSION_UDP_PORT:-9000}
2022-03-25 10:57:34 +00:00
# Unique execution layer communication port => base_port + instance * 10
base_rpcport=${BEACON_SESSION_RPC_PORT:-8551}
# Beacon sync mode, full, snap, or light
syncmode=${BEACON_SESSION_SYNCMODE:-full}
# Git branch to use with "build" command
git_branch=${BEACON_GIT_BRANCH:-kiln-dev-auth}
# Unique log data and database folder (relative to current directory)
2022-03-25 10:57:34 +00:00
datadir=${BEACON_SESSION_DATADIR:-./datadir-beacon-$name$instance}
2022-03-25 10:57:34 +00:00
# Terminal total difficulty
ttd=${BEACON_SERVER_TTD:-20000000000000}
2022-03-11 16:42:25 +00:00
2022-03-25 10:57:34 +00:00
# Adding generic options
optargs=${BEACON_SESSION_OPTARGS:-'--nat=none'}
# ------------------------------------------------------------------------------
# No need to change, below
# ------------------------------------------------------------------------------
2022-03-25 10:57:34 +00:00
# TCP/UDP communication ports
tcp_port=`expr $base_tcpport + $instance`
udp_port=`expr $base_udpport + $instance`
rpc_port=`expr $base_rpcport + $instance \* 10`
# Log spooler capacity settings
logfile_max=80000000
num_backlogs=40
2022-03-25 10:57:34 +00:00
# Base directory for finding objects in the Beacon file system
find_prefix="`dirname $0` . .. ../.."
2022-04-05 10:53:41 +00:00
find_prefix="$find_prefix ../nimbus-eth1"
2022-03-25 10:57:34 +00:00
find_prefix="$find_prefix go-ethereum ../nethermind nimbus-eth1-blobs"
find_prefix="$find_prefix ../go-ethereum ../nethermind ../nimbus-eth1-blobs"
# Sub-find directory for various items
2022-03-25 10:57:34 +00:00
find_beacon=". .. build/bin"
2022-05-10 08:44:37 +00:00
find_yamlconf="merge-testnets/$fullname $fullname"
2022-04-05 10:53:41 +00:00
find_jwtsecret=
find_jwtsecret="$find_jwtsecret datadir-geth-$name$instance"
find_jwtsecret="$find_jwtsecret datadir-nimbus-$name"
find_jwtsecret="$find_jwtsecret datadir-$name$instance"
# ------------------------------------------------------------------------------
# Helpers
# ------------------------------------------------------------------------------
# Find executable file
find_exe() { # Syntax: <exe-name> <subdir> ...
exe="$1"
shift
{
for pfx in $find_prefix; do
for sub; do
find -L \
"$pfx/$sub" \
-maxdepth 3 -type f -name "$exe" -perm /111 -print \
2>/dev/null
done
done |
# Beware, this is slow. On the other hand, uncommenting the
# next line dumps all possible matches to the console.
#tee /dev/tty |
xargs -n1 realpath 2>/dev/null
# provide argument file name as default
echo "$exe"
} | sed -eq
}
# Find non-executable file
find_file() { # Syntax: <file-name> <subdir> ...
file="$1"
shift
{
for pfx in $find_prefix; do
for sub; do
find -L \
"$pfx/$sub" \
-maxdepth 3 -type f -name "$file" -print \
2>/dev/null
done |
# Beware, this is slow. On the other hand, uncommenting the
# next line dumps all possible matches to the console.
#tee /dev/tty |
xargs -n1 realpath 2>/dev/null
done
# provide argument file name as default
echo "$file"
} | sed -eq
}
stripColors() {
if ansi2txt </dev/null 2>/dev/null
then
ansi2txt
else
cat
fi
}
# Find pid of running svlogd command
get_pid_svlogd() {
ps x|
grep \
-e "svlogd $datadir/log" \
|
grep -v \
-e vim \
-e grep \
|
awk '$1 != '"$$"'{print $1}'
}
2022-03-25 10:57:34 +00:00
# Find pid of running svlogd and beacon command
get_pids() {
2022-03-25 10:57:34 +00:00
cmd=nimbus_beacon_node
cmd="$cmd --data-dir=./data"
cmd="$cmd --web3-url=ws://127.0.0.1:$rpc_port"
cmd="$cmd --tcp-port=$tcp_port"
ps x|
grep \
2022-03-25 10:57:34 +00:00
-e "$cmd" \
-e "svlogd $datadir/log" \
|
grep -v \
-e vim \
-e grep \
|
awk '$1 != '"$$"'{print $1}'
}
# ------------------------------------------------------------------------------
# Command line parsing and man page
# ------------------------------------------------------------------------------
nohup=no
start=no
stop=no
flush=no
logs=no
help=no
2022-03-25 10:57:34 +00:00
build=no
enode=no
attch=no
test $# -ne 0 ||
help=yes
for arg
do
case "$arg" in
2022-03-25 10:57:34 +00:00
build)
build=yes
;;
enode)
enode=yes
;;
attach)
attch=yes
;;
stop)
stop=yes
;;
flush)
flush=yes
;;
start)
start=yes
;;
daemon)
nohup=yes
start=yes
;;
logs)
logs=yes
;;
help|'')
help=yes
;;
*)
exec >&2
2022-03-25 10:57:34 +00:00
echo "Usage: $self [help] [stop] [flush] [daemon|start|enode|attach] [logs]"
exit 2
esac
done
test yes != "$help" || {
cat <<EOF
$self:
Available commands (can be combined irrespective of order):
2022-03-25 10:57:34 +00:00
logs resume console logging
flush delete all log and blockchain data
2022-03-25 10:57:34 +00:00
build re-compile geth version
2022-03-25 10:57:34 +00:00
Mutually exclusive commands:
stop stop the Geth session (as descibed above)
start start the Geth session in the foreground
daemon background session (without termninating on logout, e.g. from ssh)
EOF
exit
}
# ------------------------------------------------------------------------------
# MAIN
# ------------------------------------------------------------------------------
# Check for logger program availability
(svlogd 2>&1|grep -i 'usage: svlogd' >/dev/null) || {
2022-03-25 10:57:34 +00:00
exec >&2
echo "*** $self: This script needs a working \"svlogd\" program. On Debian,"
echo " this is provided by the \"runit\" package."
exit 2
}
# Stop running sessions by sending termination signal
test yes != "$stop" || {
2022-03-25 10:57:34 +00:00
# set -x
pids=`get_pids`
test -z "$pids" || {
(set -x; kill -TERM $pids)
sleep 1
pids=`get_pids`
test -z "$pids" || {
(set -x; kill -KILL $pids)
sleep 1
}
echo
}
}
# Clean up
test yes != "$flush" || {
2022-03-25 10:57:34 +00:00
d=`basename $datadir`
test \! -d $datadir || (set -x; rm -rf $datadir)
}
# Stop here after clean up when terminating a session
test yes != "$stop" || {
2022-03-25 10:57:34 +00:00
exit
}
if [ yes = "$nohup" ]
then
2022-03-25 10:57:34 +00:00
true
elif [ yes != "$flush" -a yes != "$build" ]
then
2022-03-25 10:57:34 +00:00
# Set logging unless deamon enabled or build
logs=yes
fi
2022-03-25 10:57:34 +00:00
# Rebuild Getn version
test yes != "$build" || (
set -x
git checkout "$git_branch"
git pull origin "$git_branch"
make update OVERRIDE=1
make nimbus_beacon_node
) || exit
# Start a new geth session in the background
test yes != "$start" || (
mkdir -p $datadir/log $datadir/data
2022-03-25 10:57:34 +00:00
beacon=`find_exe nimbus_beacon_node $find_beacon`
jwtsecret=`find_file jwtsecret $find_jwtsecret`
yamlconf=`find_file config.yaml $find_yamlconf`
confdir=`dirname "$yamlconf"`
test yes != "$nohup" || {
trap "echo '*** $self: NOHUP ignored'" HUP
trap "echo '*** $self: terminating ..';exit" INT TERM QUIT
}
(
cd $datadir
mv ./log/config ./log/config~ 2>/dev/null || true
{
echo s$logfile_max
echo n$num_backlogs
} >./log/config
set -x
2022-03-25 10:57:34 +00:00
${beacon:-nimbus_beacon_node} \
--data-dir=./data \
--web3-url=ws://127.0.0.1:$rpc_port \
--tcp-port=$tcp_port \
--udp-port=$udp_port \
--network=$confdir \
--jwt-secret=$jwtsecret \
--terminal-total-difficulty-override=$ttd \
--rest \
--metrics \
$optargs \
--log-level=DEBUG \
--non-interactive \
2>&1
) | stripColors | svlogd $datadir/log
) &
# After starting a session, make sure that svlogd is re-loaded in order
# to read the config file (woul not tdo it right on the start)
test yes != "$start" || {
sleep 1
pid=`get_pid_svlogd`
test -z "$pid" || kill -HUP $pid
echo
}
# Logging ...
test yes != "$logs" || {
mkdir -p $datadir/log/
touch $datadir/log/current |
tail -F $datadir/log/current |
# Filter out chaff on console data
grep -v \
2022-03-25 10:57:34 +00:00
-e '>> [NPF]' \
-e '<< [NPF]'
}
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------