From 59b1a4772cee351cdeab9933632fda8074a0c7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Thu, 5 Aug 2021 10:49:34 +0200 Subject: [PATCH] don't try to use lsof on Windows (#2762) --- scripts/launch_local_testnet.sh | 29 ++++++++++++++++------------- tests/simulation/restapi.sh | 28 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/scripts/launch_local_testnet.sh b/scripts/launch_local_testnet.sh index c4ae6efec..1a987f1a7 100755 --- a/scripts/launch_local_testnet.sh +++ b/scripts/launch_local_testnet.sh @@ -187,12 +187,14 @@ mkdir -p "${NETWORK_DIR}" USER_VALIDATORS=8 TOTAL_VALIDATORS=128 +HAVE_LSOF=0 # Windows detection if uname | grep -qiE "mingw|msys"; then MAKE="mingw32-make" else MAKE="make" + which lsof &>/dev/null && HAVE_LSOF=1 || { echo "'lsof' not installed and we need it to check for ports already in use. Aborting."; exit 1; } fi # number of CPU cores @@ -203,21 +205,22 @@ else fi # kill lingering processes from a previous run -which lsof &>/dev/null || { echo "'lsof' not installed. Aborting."; exit 1; } -for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do - for PORT in $(( BASE_PORT + NUM_NODE )) $(( BASE_METRICS_PORT + NUM_NODE )) $(( BASE_RPC_PORT + NUM_NODE )); 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 +if [[ "${HAVE_LSOF}" == "1" ]]; then + for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do + for PORT in $(( BASE_PORT + NUM_NODE )) $(( BASE_METRICS_PORT + NUM_NODE )) $(( BASE_RPC_PORT + NUM_NODE )); 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 done -done +fi # Build the binaries BINARIES="nimbus_beacon_node nimbus_signing_process nimbus_validator_client deposit_contract" diff --git a/tests/simulation/restapi.sh b/tests/simulation/restapi.sh index 5c0ce5f3a..2b61107c8 100755 --- a/tests/simulation/restapi.sh +++ b/tests/simulation/restapi.sh @@ -115,11 +115,14 @@ MKDIR_SCRIPT="${GIT_ROOT}/scripts/makedir.sh" $MKDIR_SCRIPT "${TEST_DIR}" +HAVE_LSOF=0 + # Windows detection if uname | grep -qiE "mingw|msys"; then MAKE="mingw32-make" else MAKE="make" + which lsof &>/dev/null && HAVE_LSOF=1 || { echo "'lsof' not installed and we need it to check for ports already in use. Aborting."; exit 1; } fi # number of CPU cores @@ -130,19 +133,20 @@ else 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 +if [[ "${HAVE_LSOF}" == "1" ]]; then + 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 -done +fi build_if_missing () { if [[ ! -e "${GIT_ROOT}/build/${1}" ]]; then