Test availability of thin and websocket ports before start.

Improving cmd line scanning, handling thin options in front of
-p <port>. Also clean up test usage, just use if/then and [].
This commit is contained in:
Alec Leamas 2010-10-16 11:38:25 +02:00
parent e7efd5fbf7
commit bb67b1231b

View file

@ -3,38 +3,48 @@
# Start diaspora websocket and main services # Start diaspora websocket and main services
# #
# Is someone listening on the port already? (ipv4 only test ?)
PORT=3000 PORT=3000
while getopts ":p:" OPTION THIN_ARGS="$@"
do while [ $# -gt 0 ]; do
if [ $OPTION == 'p' ] if [ "$1" = '-p' ]; then
then PORT="$2"
PORT=$OPTARG break
fi fi
shift
done done
services=$( netstat -nl | grep ":$PORT[ \t]") # Is someone listening on the ports already? (ipv4 only test ?)
services=$( netstat -nl | grep '[^:]:'$PORT'[ \t]')
test -n "$services" && { if [ -n "$services" ]; then
echo "Warning: something is already using port "$PORT echo "Error: something is already using thin port $PORT. Exiting" >&2
echo " $services" echo " $services"
exit exit 64
} fi
services=$( netstat -nl | grep '[^:]:8080[ \t]')
if [ -n "$services" ]; then
echo "Error: something is already using websocket port 8080. Exiting" >&2
echo " $services"
exit 64
fi
# Check if Mongo is running # Check if Mongo is running
if ! pgrep mongod >/dev/null
if ! ps ax | grep -v grep | grep mongod >/dev/null
then then
echo "Mongod not started" echo "Error: Mongod not started. Exiting" >&2
else exit 64
mkdir -p -v log/thin/
#force AGPL
test -w public -a ! -e public/source.tar.gz &&
tar czf public/source.tar.gz --exclude='source.tar.gz' -X .gitignore *
test -e public/source.tar.gz || {
echo "Can't find, or even create, public/source.tar.gz. Giving up"
exit 2
}
bundle exec ruby ./script/websocket_server.rb&
bundle exec thin start $@
fi fi
# Force AGPL
if [ -w public -a ! -e public/source.tar.gz ]; then
tar czf public/source.tar.gz --exclude='source.tar.gz' -X .gitignore *
fi
if [ ! -e public/source.tar.gz ]; then
echo "Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
exit 65
fi
mkdir -p -v log/thin/
bundle exec ruby ./script/websocket_server.rb&
bundle exec thin start $THIN_ARGS