nimbus-eth2/scripts/run-beacon-node.sh
Jacek Sieka 233d756518
Logging and startup improvements (#3038)
* Logging and startup improvements

Color support for released binaries!

* startup scripts no longer log to file by default - this only affects
source builds - released binaries don't support file logging
* add --log-stdout option to control logging to stdout (colors, json)
* detect tty:s vs redirected logs and log accordingly
* add option to disable log colors at runtime
* simplify several "common" logs, showing the most important information
earlier and more clearly
* remove line numbers / file information / tid - these take up space and
are of little use to end users
  * still enabled in debug builds and tools
* remove `testnet_servers_image` compile-time option
* server images, released binaries and compile-from-source now offer
the same behaviour and features
* fixes https://github.com/status-im/nimbus-eth2/issues/2326
* fixes https://github.com/status-im/nimbus-eth2/issues/1794
* remove instanteneous block speed from sync message, keeping only
average

before:

```
INF 2021-10-28 16:45:59.000+02:00 Slot start                                 topics="beacnde" tid=386429 file=nimbus_beacon_node.nim:884 lastSlot=2384027 wallSlot=2384028 delay=461us84ns peers=0 head=75a10ee5:3348 headEpoch=104 finalized=cd6804ba:3264 finalizedEpoch=102 sync="wwwwwwwwww:0:0.0000:0.0000:00h00m (3348)"
INF 2021-10-28 16:45:59.046+02:00 Slot end                                   topics="beacnde" tid=386429 file=nimbus_beacon_node.nim:821 slot=2384028 nextSlot=2384029 head=75a10ee5:3348 headEpoch=104 finalizedHead=cd6804ba:3264 finalizedEpoch=102 nextAttestationSlot=-1 nextProposalSlot=-1 nextActionWait=n/a
```

after:

```
INF 2021-10-28 22:43:23.033+02:00 Slot start                                 topics="beacnde" slot=2385815 epoch=74556 sync="DDPDDPUDDD:10:5.2258:01h19m (2361088)" peers=37 head=eacd2dae:2361096 finalized=73782:a4751487 delay=33ms687us715ns
INF 2021-10-28 22:43:23.291+02:00 Slot end                                   topics="beacnde" slot=2385815 nextActionWait=n/a nextAttestationSlot=-1 nextProposalSlot=-1 head=eacd2dae:2361096
```

* fix comment

* documentation updates

* mention `--log-file` may be deprecated in the future
* update various docs
2021-11-02 18:06:36 +01:00

105 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2020-2021 Status Research & Development GmbH. Licensed under
# either of:
# - Apache License, version 2.0
# - MIT license
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
set -e
cd "$(dirname $0)/.."
NBC_BINARY=$1
shift
NETWORK=$1
shift
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
cat <<HELP
All supplied options will be forwarded to the beacon node executable.
Please execute build/$NBC_BINARY --help to get more information.
To suppress the interactive input required by this script, you can
specify WEB3_URL as an environment variable.
HELP
exit 0
fi
: ${NODE_ID:=0}
: ${DATA_DIR_NAME:="shared_${NETWORK}_${NODE_ID}"}
: ${DATA_DIR:="build/data/${DATA_DIR_NAME}"}
: ${BASE_P2P_PORT:=9000}
: ${BASE_RPC_PORT:=9190}
: ${BASE_REST_PORT:=5052}
# Windows detection
if uname | grep -qiE "mingw|msys"; then
MAKE="mingw32-make"
# This "winpty" wrapper is needed to make Ctrl+C work, on some systems.
WINPTY="winpty --"
else
MAKE="make"
WINPTY=""
fi
if [[ ! -f build/${NBC_BINARY} ]]; then
cat << MISSING_BINARY_HELP
Please build the beacon node binary by executing the following command:
${MAKE} ${NBC_BINARY}
MISSING_BINARY_HELP
exit 1
fi
WEB3_URL_OPT_PRESENT=0
for op in "$@"; do
if [[ "${op}" =~ ^--web3-url=.*$ ]]; then
WEB3_URL_OPT_PRESENT=1
break
fi
done
if [[ "${WEB3_URL}" == "" && "${WEB3_URL_OPT_PRESENT}" == "0" ]]; then
cat <<WEB3_HELP
To monitor the Eth1 validator deposit contract, you'll need to pair
the Nimbus beacon node with a Web3 provider capable of serving Eth1
event logs. This could be a locally running Eth1 client such as Geth
or a cloud service such as Infura. For more information please see
our setup guides:
https://nimbus.guide/eth1.html
WEB3_HELP
echo -n "Please enter a Web3 provider URL: "
read WEB3_URL
fi
EXTRA_ARGS=""
if [[ "${WEB3_URL}" != "" ]]; then
EXTRA_ARGS="--web3-url=${WEB3_URL}"
fi
# Allow the binary to receive signals directly.
exec ${WINPTY} build/${NBC_BINARY} \
--network=${NETWORK} \
--data-dir="${DATA_DIR}" \
--tcp-port=$(( ${BASE_P2P_PORT} + ${NODE_ID} )) \
--udp-port=$(( ${BASE_P2P_PORT} + ${NODE_ID} )) \
--rest \
--rest-port=$(( ${BASE_REST_PORT} + ${NODE_ID} )) \
--rpc \
--rpc-port=$(( ${BASE_RPC_PORT} +${NODE_ID} )) \
--metrics \
${EXTRA_ARGS} \
$@