Add mechanism to determine when a node has finished booting

This commit is contained in:
Michael Vines 2019-01-22 11:34:12 -08:00 committed by Grimes
parent f630b50902
commit cc88f9bcd6
3 changed files with 59 additions and 31 deletions

View File

@ -180,6 +180,13 @@ fn main() {
.takes_value(true)
.help("RPC port to use for this node"),
)
.arg(
Arg::with_name("init_complete_file")
.long("init-complete-file")
.value_name("FILE")
.takes_value(true)
.help("Create this file, if it doesn't already exist, once node initialization is complete"),
)
.get_matches();
let no_sigverify = matches.is_present("nosigverify");
@ -210,6 +217,7 @@ fn main() {
solana_netutil::find_available_port_in_range(FULLNODE_PORT_RANGE)
.expect("unable to allocate rpc port")
};
let init_complete_file = matches.value_of("init_complete_file");
let keypair = Arc::new(keypair);
let node = Node::new_with_external_ip(keypair.pubkey(), &gossip);
@ -258,6 +266,10 @@ fn main() {
}
}
if let Some(filename) = init_complete_file {
File::create(filename).unwrap_or_else(|_| panic!("Unable to create: {}", filename));
}
info!("Node initialized");
loop {
let status = fullnode.handle_role_transition();
match status {

View File

@ -29,16 +29,22 @@ else
program="$solana_fullnode"
fi
maybe_init_complete_file=
maybe_no_leader_rotation=
if [[ $1 = --no-leader-rotation ]]; then
maybe_no_leader_rotation="--no-leader-rotation"
shift
fi
if [[ -n $1 ]]; then
echo "Unknown argument: $1"
exit 1
fi
while [[ -n $1 ]]; do
if [[ $1 = --init-complete-file ]]; then
maybe_init_complete_file="--init-complete-file $2"
shift 2
elif [[ $1 = --no-leader-rotation ]]; then
maybe_no_leader_rotation="--no-leader-rotation"
shift
else
echo "Unknown argument: $1"
exit 1
fi
done
if [[ -d $SNAP ]]; then
if [[ $(snapctl get leader-rotation) = false ]]; then
@ -50,7 +56,10 @@ tune_system
trap 'kill "$pid" && wait "$pid"' INT TERM
$solana_ledger_tool --ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger verify
# shellcheck disable=SC2086 # Don't want to double quote maybe_init_complete_file
$program \
$maybe_init_complete_file \
$maybe_no_leader_rotation \
--identity "$SOLANA_CONFIG_DIR"/bootstrap-leader.json \
--ledger "$SOLANA_CONFIG_DIR"/bootstrap-leader-ledger \

View File

@ -21,7 +21,7 @@ usage() {
echo
fi
cat <<EOF
usage: $0 [-x] [--no-leader-rotation] [--rpc-port port] [rsync network path to bootstrap leader configuration] [network entry point]
usage: $0 [-x] [--no-leader-rotation] [--init-complete-file FILE] [--rpc-port port] [rsync network path to bootstrap leader configuration] [network entry point]
Start a full node on the specified network
@ -29,6 +29,7 @@ Start a full node on the specified network
-X [label] - start or restart a dynamically-configured full node with
the specified label
--no-leader-rotation - disable leader rotation
--init-complete-file FILE - create this file, if it doesn't already exist, once node initialization is complete
--rpc-port port - custom RPC port for this node
EOF
@ -39,29 +40,34 @@ if [[ $1 = -h ]]; then
usage
fi
if [[ $1 = -X ]]; then
self_setup=1
self_setup_label=$2
shift 2
elif [[ $1 = -x ]]; then
self_setup=1
self_setup_label=$$
shift
else
self_setup=0
fi
maybe_init_complete_file=
maybe_no_leader_rotation=
if [[ $1 = --no-leader-rotation ]]; then
maybe_no_leader_rotation="--no-leader-rotation"
shift
fi
self_setup=0
maybe_rpc_port=
if [[ $1 = --rpc-port ]]; then
maybe_rpc_port="$1 $2"
shift 2
fi
while [[ ${1:0:1} = - ]]; do
if [[ $1 = -X ]]; then
self_setup=1
self_setup_label=$2
shift 2
elif [[ $1 = -x ]]; then
self_setup=1
self_setup_label=$$
shift
elif [[ $1 = --init-complete-file ]]; then
maybe_init_complete_file="--init-complete-file $2"
shift 2
elif [[ $1 = --no-leader-rotation ]]; then
maybe_no_leader_rotation="--no-leader-rotation"
shift
elif [[ $1 = --rpc-port ]]; then
maybe_rpc_port="$1 $2"
shift 2
else
echo "Unknown argument: $1"
exit 1
fi
done
if [[ -d $SNAP ]]; then
if [[ $(snapctl get leader-rotation) = false ]]; then
@ -230,8 +236,9 @@ if [[ ! -d "$ledger_config_dir" ]]; then
fi
trap 'kill "$pid" && wait "$pid"' INT TERM
# shellcheck disable=SC2086 # Don't want to double quote # maybe_rpc_port
# shellcheck disable=SC2086 # Don't want to double quote maybe_rpc_port or maybe_init_complete_file
$program \
$maybe_init_complete_file \
$maybe_no_leader_rotation \
$maybe_rpc_port \
--identity "$fullnode_json_path" \