From c574dbda90b22baa69f18cce250f64d1d89fae8f Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 19 Feb 2016 17:19:50 +0800 Subject: [PATCH] FEATURE: Exit launcher and warn if ports to expose are in use. --- launcher | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/launcher b/launcher index a8c3416..7558a64 100755 --- a/launcher +++ b/launcher @@ -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 @@ -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']"` -- 2.25.1