From a97f319ba05917fd6e385c3196a1d353af8c4e73 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Fri, 23 Nov 2018 09:56:31 +0100 Subject: [PATCH] Offer to kill process taking port 8081 when starting react-native Signed-off-by: Pedro Pombeiro --- Makefile | 2 +- scripts/start-react-native.sh | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100755 scripts/start-react-native.sh diff --git a/Makefile b/Makefile index a87e30947a..d2b11ac638 100644 --- a/Makefile +++ b/Makefile @@ -177,7 +177,7 @@ test-auto: ##@test Run tests in interactive (auto) mode in NodeJS # Other #-------------- react-native: ##@other Start react native packager - react-native start + @scripts/start-react-native.sh geth-connect: ##@other Connect to Geth on the device adb forward tcp:8545 tcp:8545 diff --git a/scripts/start-react-native.sh b/scripts/start-react-native.sh new file mode 100755 index 0000000000..e923911d3f --- /dev/null +++ b/scripts/start-react-native.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +METRO_PORT=8081 +METRO_PID="$(lsof -i :${METRO_PORT} | awk 'NR!=1 {print $2}')" +if [ ! -z $METRO_PID ]; then + echo -e "${YELLOW}TCP port ${METRO_PORT} is required by the Metro packager.\nThe following process currently has the port open, preventing Metro from starting:${NC}" + ps -fp $METRO_PID + echo -e "${YELLOW}Do you want to terminate it (y/n)?${NC}" + read -n 1 term + [[ $term == 'y' ]] && kill $METRO_PID +fi + +react-native start