Skip to content

Commit

Permalink
Merge pull request #222 from tgxworld/port_in_use_warning
Browse files Browse the repository at this point in the history
FEATURE: Exit launcher and warn if ports to expose are in use.
  • Loading branch information
SamSaffron committed Feb 21, 2016
2 parents 6ca9e76 + c574dbd commit c7821ea
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion launcher
Expand Up @@ -200,6 +200,18 @@ check_resources() {
fi
}

check_ports() {
local valid=$(netstat -tln | awk '{print $4}' | grep ":${1}\$")

if [ -n "$valid" ]; then
echo "Launcher has detected that port ${1} is in use."
echo ""
echo "If you are trying to run Discourse simultaneously with another web server like Apache or nginx, you will need to bind to a different port."
echo "See https://meta.discourse.org/t/17247 for help."
exit 1
fi
}

if [ "$opt" != "--skip-prereqs" ] ; then
prereqs
fi
Expand Down Expand Up @@ -470,7 +482,18 @@ run_start(){

host_run
ports=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
"require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| '-p ' << p.to_s << ' '}.join"`
"require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| \"-p #{p}\"}.join(' ')"`

IFS='-p ' read -a array <<< "$ports"
for element in "${array[@]}"
do
IFS=':' read -a args <<< "$element"
if [ "${#args[@]}" == "2" ]; then
check_ports "${args[0]}"
elif [ "${#args[@]}" == "3" ]; then
check_ports "${args[1]}"
fi
done

docker_args=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \
"require 'yaml'; puts YAML.load(STDIN.readlines.join)['docker_args']"`
Expand Down

0 comments on commit c7821ea

Please sign in to comment.