Add a configuration file
Adds a config file with environment and default thin options
This commit is contained in:
parent
ed8878c72a
commit
fcd70ce152
2 changed files with 25 additions and 14 deletions
11
config/server.sh
Normal file
11
config/server.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#
|
||||||
|
# Included by script/server
|
||||||
|
#
|
||||||
|
THIN_PORT=3000
|
||||||
|
SOCKET_PORT=8080
|
||||||
|
|
||||||
|
# See thin -h for possible values.
|
||||||
|
DEFAULT_THIN_ARGS="-p $THIN_PORT"
|
||||||
|
|
||||||
|
# Uncomment to run in production mode.
|
||||||
|
#export RAILS_ENV="production rails server"
|
||||||
|
|
@ -6,27 +6,28 @@
|
||||||
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
||||||
cd $( dirname $realpath)/..
|
cd $( dirname $realpath)/..
|
||||||
|
|
||||||
PORT=3000
|
[ -e config/server.sh ] && source config/server.sh
|
||||||
THIN_ARGS="$@"
|
|
||||||
while [ $# -gt 0 ]; do
|
# Scan for -p, find out what port thin is about to use.
|
||||||
if [ "$1" = '-p' ]; then
|
args="$DEFAULT_THIN_ARGS $@"
|
||||||
PORT="$2"
|
prev_arg=''
|
||||||
break
|
for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
|
||||||
fi
|
do
|
||||||
shift
|
[ "$prev_arg" = '-p' ] && THIN_PORT="$arg"
|
||||||
|
prev_arg="$arg"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Is someone listening on the ports already? (ipv4 only test ?)
|
# Is someone listening on the ports already? (ipv4 only test ?)
|
||||||
services=$( netstat -nl | grep '[^:]:'$PORT'[ \t]')
|
services=$( netstat -nl | grep '[^:]:'$THIN_PORT'[ \t]')
|
||||||
if [ -n "$services" ]; then
|
if [ -n "$services" ]; then
|
||||||
echo "Error: something is already using thin port $PORT. Exiting" >&2
|
echo "Error: thin port $THIN_PORT is already in use. Exiting" >&2
|
||||||
echo " $services"
|
echo " $services"
|
||||||
exit 64
|
exit 64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
services=$( netstat -nl | grep '[^:]:8080[ \t]')
|
services=$( netstat -nl | grep '[^:]:'$SOCKET_PORT'[ \t]')
|
||||||
if [ -n "$services" ]; then
|
if [ -n "$services" ]; then
|
||||||
echo "Error: something is already using websocket port 8080. Exiting" >&2
|
echo "Error: websocket port $SOCKET_PORT is already in use. Exiting" >&2
|
||||||
echo " $services"
|
echo " $services"
|
||||||
exit 64
|
exit 64
|
||||||
fi
|
fi
|
||||||
|
|
@ -49,5 +50,4 @@ fi
|
||||||
|
|
||||||
mkdir -p -v log/thin/
|
mkdir -p -v log/thin/
|
||||||
bundle exec ruby ./script/websocket_server.rb&
|
bundle exec ruby ./script/websocket_server.rb&
|
||||||
bundle exec thin start $THIN_ARGS
|
bundle exec thin start $args
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue