Skip to content

Instantly share code, notes, and snippets.

@pavelsr
Last active October 18, 2018 09:05
Show Gist options
  • Save pavelsr/3cceaec2c245321f3736ae9cc09a27b7 to your computer and use it in GitHub Desktop.
Save pavelsr/3cceaec2c245321f3736ae9cc09a27b7 to your computer and use it in GitHub Desktop.
Morbo: Solution of Can't create listen socket: Address already in use problem
#!/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
@pavelsr
Copy link
Author

pavelsr commented Nov 23, 2017

Installation:

sudo wget https://gist.githubusercontent.com/pavelsr/3cceaec2c245321f3736ae9cc09a27b7/raw/b897c8877a7916d7edc23d199971d909f486e457/dev.sh -O /usr/local/bin/morbo2
sudo chmod +x /usr/local/bin/morbo2

@pavelsr
Copy link
Author

pavelsr commented Apr 7, 2018

Проблема: не показывает порты с docker

@YordanGeorgiev
Copy link

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"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment