#!/usr/bin/env bash # # Start a fullnode # here=$(dirname "$0") # shellcheck source=multinode-demo/common.sh source "$here"/common.sh # shellcheck source=scripts/oom-score-adj.sh source "$here"/../scripts/oom-score-adj.sh fullnode_usage() { if [[ -n $1 ]]; then echo "$*" echo fi cat </dev/null 2>&1 } set -e PS4="$(basename "$0"): " while true; do if [[ ! -d "$SOLANA_RSYNC_CONFIG_DIR"/ledger ]]; then if [[ $node_type = bootstrap_leader ]]; then ledger_not_setup "$SOLANA_RSYNC_CONFIG_DIR/ledger does not exist" fi $rsync -vPr "${rsync_entrypoint_url:?}"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" fi if new_gensis_block; then # If the genesis block has changed remove the now stale ledger and vote # keypair for the node and start all over again ( set -x rm -rf "$ledger_config_dir" "$accounts_config_dir" \ "$fullnode_vote_keypair_path".configured "$replicator_storage_keypair_path".configured ) fi if [[ ! -d "$ledger_config_dir" ]]; then cp -a "$SOLANA_RSYNC_CONFIG_DIR"/ledger/ "$ledger_config_dir" $solana_ledger_tool --ledger "$ledger_config_dir" verify fi trap '[[ -n $pid ]] && kill "$pid" >/dev/null 2>&1 && wait "$pid"' INT TERM ERR if [[ $node_type = validator ]] && ((stake)); then setup_vote_and_stake_accounts "${entrypoint_address%:*}" "$fullnode_keypair_path" "$fullnode_vote_keypair_path" "$fullnode_stake_keypair_path" "$stake" elif [[ $node_type = replicator ]] && ((stake)); then setup_replicator_account "${entrypoint_address%:*}" "$replicator_keypair_path" "$stake" fi echo "$PS4$program ${args[*]}" $program "${args[@]}" & pid=$! oom_score_adj "$pid" 1000 if ((no_restart)); then wait "$pid" exit $? fi if [[ $node_type = bootstrap_leader ]]; then wait "$pid" sleep 1 else secs_to_next_genesis_poll=1 while true; do if ! kill -0 "$pid"; then wait "$pid" exit 0 fi sleep 1 ((poll_for_new_genesis_block)) || continue ((secs_to_next_genesis_poll--)) && continue ( set -x $rsync -r "${rsync_entrypoint_url:?}"/config/ledger "$SOLANA_RSYNC_CONFIG_DIR" ) || true new_gensis_block && break secs_to_next_genesis_poll=60 done echo "############## New genesis detected, restarting $node_type ##############" kill "$pid" || true wait "$pid" || true # give the cluster time to come back up ( set -x sleep 60 ) fi done