-
-
Save pavelsr/3cceaec2c245321f3736ae9cc09a27b7 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# run it with ./dev.sh | |
# Morbo: Solution of Can't create listen socket: Address already in use problem | |
APP=$1 | |
START_PORT=3000 | |
BUSY_PORTS=$(netstat -lntu | awk '{print $4}' | grep ':' | cut -d ":" -f 2 | sort -g | uniq | awk '$1>=$START_PORT') | |
echo $BUSY_PORTS | |
# while [[ ${BUSY_PORTS[*]} != "$port" ]] | |
# while containsElement $port ${BUSY_PORTS[@]} | |
# while [[ echo $BUSY_PORTS | grep $port ]] | |
# while [[ -n "${BUSY_PORTS[$port]}" ]] | |
# while [[ ${BUSY_PORTS[*]} =~ "$port" ]] | |
PORT_TO_RUN=3000 | |
while [[ "${BUSY_PORTS[*]}" == *"$PORT_TO_RUN"* ]] | |
do | |
PORT_TO_RUN=$[PORT_TO_RUN+1] | |
done | |
# echo "$PORT_TO_RUN" | |
morbo $APP -l "http://*:$PORT_TO_RUN" | |
# Thanks to | |
# https://superuser.com/questions/529830/get-a-list-of-open-ports-in-linux | |
# https://stackoverflow.com/questions/1527049/join-elements-of-an-array | |
# http://www.linuxjournal.com/content/bash-arrays |
Проблема: не показывает порты с docker
doMojoMorboStop(){
should_exit=${1:-}
test -z "${should_exit:-}" && should_exit=1
test -z "${mojo_morbo_port:-}" && export mojo_morbo_port=3001
found=0
doLog "DEBUG START doMojoMorboStop"
echo -e "\n"
while read -r child_of_1_pid; do
while read -r listening_on_port_pid; do
while read -r pid_to_kill; do
echo killing the following pid_to_kill $pid_to_kill;
kill -9 $pid_to_kill
found=1
done < <(ps -ef | grep $child_of_1_pid|grep issue_tracker|grep -v grep|awk '{print $2}');
done < <(lsof -i:${mojo_morbo_port:-} -t|grep $child_of_1_pid)
done < <(pgrep -P 1);
not_found_msg="morbo is NOT running for the mojo_morbo_port: "${mojo_morbo_port:-}" of this product instance"
if [ "${should_exit:-}" -eq 1 ]; then
test $found -eq 0 && doExit 1 $not_found_msg
else
test $found -eq 0 && doLog INFO $not_found_msg
fi
echo -e "\n"
doLog "DEBUG STOP doMojoMorboStop"
}
Installation: