restapi.sh: prevent port clashes (#2746)
This commit is contained in:
parent
f0321d2eb5
commit
17c94c4d8e
|
@ -45,7 +45,12 @@ def runStages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("REST test suite") {
|
stage("REST test suite") {
|
||||||
sh "./tests/simulation/restapi.sh --data-dir resttest0_data --base-port \$(( 9100 + EXECUTOR_NUMBER * 100 )) --base-rest-port \$(( 7100 + EXECUTOR_NUMBER * 100 )) --base-metrics-port \$(( 8108 + EXECUTOR_NUMBER * 100 )) --sleep-timeout 30"
|
sh """#!/bin/bash
|
||||||
|
set -e
|
||||||
|
./tests/simulation/restapi.sh --data-dir resttest0_data --base-port \$(( 9100 + EXECUTOR_NUMBER * 100 )) \
|
||||||
|
--base-rest-port \$(( 7100 + EXECUTOR_NUMBER * 100 )) --base-metrics-port \
|
||||||
|
\$(( 8108 + EXECUTOR_NUMBER * 100 )) --sleep-timeout 30 --kill-old-processes
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
stage("Testnet finalization") {
|
stage("Testnet finalization") {
|
||||||
|
|
|
@ -315,6 +315,12 @@ cleanup() {
|
||||||
sleep 2
|
sleep 2
|
||||||
pkill -f -9 -P $$ nimbus_beacon_node &>/dev/null || true
|
pkill -f -9 -P $$ nimbus_beacon_node &>/dev/null || true
|
||||||
pkill -f -9 -P $$ nimbus_validator_client &>/dev/null || true
|
pkill -f -9 -P $$ nimbus_validator_client &>/dev/null || true
|
||||||
|
|
||||||
|
# Delete the binaries we just built, because these are unusable outside this
|
||||||
|
# local testnet.
|
||||||
|
for BINARY in ${BINARIES}; do
|
||||||
|
rm build/${BINARY}
|
||||||
|
done
|
||||||
}
|
}
|
||||||
trap 'cleanup' SIGINT SIGTERM EXIT
|
trap 'cleanup' SIGINT SIGTERM EXIT
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ BASE_METRICS_PORT="48008"
|
||||||
BASE_REST_PORT="47000"
|
BASE_REST_PORT="47000"
|
||||||
TIMEOUT_DURATION="30"
|
TIMEOUT_DURATION="30"
|
||||||
TEST_DIRNAME="resttest0_data"
|
TEST_DIRNAME="resttest0_data"
|
||||||
|
KILL_OLD_PROCESSES="0"
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# argument parsing #
|
# argument parsing #
|
||||||
|
@ -27,7 +28,7 @@ if [ ${PIPESTATUS[0]} != 4 ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OPTS="h"
|
OPTS="h"
|
||||||
LONGOPTS="help,data-dir:,base-port:,base-rest-port:,base-metrics-port:,sleep-timeout:"
|
LONGOPTS="help,data-dir:,base-port:,base-rest-port:,base-metrics-port:,sleep-timeout:,kill-old-processes"
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -39,6 +40,7 @@ Usage: $(basename "$0") [OPTIONS] -- [BEACON NODE OPTIONS]
|
||||||
--base-rest-port bootstrap node's REST port (default: ${BASE_REST_PORT})
|
--base-rest-port bootstrap node's REST port (default: ${BASE_REST_PORT})
|
||||||
--base-metrics-port bootstrap node's metrics server port (default: ${BASE_METRICS_PORT})
|
--base-metrics-port bootstrap node's metrics server port (default: ${BASE_METRICS_PORT})
|
||||||
--sleep-timeout timeout in seconds (default: ${TIMEOUT_DURATION} seconds)
|
--sleep-timeout timeout in seconds (default: ${TIMEOUT_DURATION} seconds)
|
||||||
|
--kill-old-processes if any process is found listening on a port we use, kill it (default: disabled)
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +78,10 @@ while true; do
|
||||||
TIMEOUT_DURATION="$2"
|
TIMEOUT_DURATION="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--kill-old-processes)
|
||||||
|
KILL_OLD_PROCESSES="1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
|
@ -88,7 +94,6 @@ while true; do
|
||||||
done
|
done
|
||||||
|
|
||||||
NUM_VALIDATORS=${VALIDATORS:-32}
|
NUM_VALIDATORS=${VALIDATORS:-32}
|
||||||
TOTAL_NODES=${NODES:-1}
|
|
||||||
GIT_ROOT="$(git rev-parse --show-toplevel)"
|
GIT_ROOT="$(git rev-parse --show-toplevel)"
|
||||||
TEST_DIR="${TEST_DIRNAME}"
|
TEST_DIR="${TEST_DIRNAME}"
|
||||||
LOG_NODE_FILE="${TEST_DIR}/node_log.txt"
|
LOG_NODE_FILE="${TEST_DIR}/node_log.txt"
|
||||||
|
@ -124,6 +129,21 @@ else
|
||||||
NPROC="$(nproc)"
|
NPROC="$(nproc)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# kill lingering processes from a previous run
|
||||||
|
which lsof &>/dev/null || { echo "'lsof' not installed. Aborting."; exit 1; }
|
||||||
|
for PORT in ${BASE_PORT} ${BASE_METRICS_PORT} ${BASE_REST_PORT}; do
|
||||||
|
for PID in $(lsof -n -i tcp:${PORT} -sTCP:LISTEN -t); do
|
||||||
|
echo -n "Found old process listening on port ${PORT}, with PID ${PID}. "
|
||||||
|
if [[ "${KILL_OLD_PROCESSES}" == "1" ]]; then
|
||||||
|
echo "Killing it."
|
||||||
|
kill -9 ${PID} || true
|
||||||
|
else
|
||||||
|
echo "Aborting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
build_if_missing () {
|
build_if_missing () {
|
||||||
if [[ ! -e "${GIT_ROOT}/build/${1}" ]]; then
|
if [[ ! -e "${GIT_ROOT}/build/${1}" ]]; then
|
||||||
${MAKE} -C "${GIT_ROOT}" -j ${NPROC} ${1}
|
${MAKE} -C "${GIT_ROOT}" -j ${NPROC} ${1}
|
||||||
|
|
Loading…
Reference in New Issue