diaspora/script/server
Alec Leamas bb67b1231b 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 [].
2010-10-19 08:26:43 +02:00

50 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
#
# Start diaspora websocket and main services
#
PORT=3000
THIN_ARGS="$@"
while [ $# -gt 0 ]; do
if [ "$1" = '-p' ]; then
PORT="$2"
break
fi
shift
done
# Is someone listening on the ports already? (ipv4 only test ?)
services=$( netstat -nl | grep '[^:]:'$PORT'[ \t]')
if [ -n "$services" ]; then
echo "Error: something is already using thin port $PORT. Exiting" >&2
echo " $services"
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
if ! pgrep mongod >/dev/null
then
echo "Error: Mongod not started. Exiting" >&2
exit 64
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