diaspora/script/server
Alec Leamas 9cd08bac67 Extended sub-uri support.
Adds new routing in routes.rb based on pod_uri. Assets are handled by a symlink
in public when using sub-uri. Various clean-up, removing thin and socket port
settings from server.sh (these are now taken from pod_uri and socket_port).

Basic functionality when setting a sub_uri like http://example.org/diaspora
now seems OK. Closes .http://joindiaspora.com/issues/737, and partially
http://joindiaspora.com/issues/391. Ports are yet to be defined and handled
in this context.

Conflicts:

	app/views/layouts/application.html.haml
	config/routes.rb
2010-12-21 01:13:15 +01:00

145 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
#
# Start diaspora websocket and main services
#
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
cd $( dirname $realpath)/..
OS=`uname -s`
[ -e config/server.sh ] && source config/server.sh
function init_public
# Create all dynamically generated files in public/ folder
{
sub_uri=$(./script/get_env.sh pod_uri.path)
if [ -n "$sub_uri" ]; then
cd public; ln -sf . ${sub_uri##/}; cd ..
fi
bundle exec thin \
-d --pid log/thin.pid --address localhost --port $THIN_PORT \
start
pod_url=$(./script/get_env.sh pod_url)
for ((i = 0; i < 30; i += 1)) do
sleep 2
wget -q -O tmp/server.html "$pod_url" && \
rm tmp/server.html && break
done
bundle exec thin --pid log/thin.pid stop
if [ -e tmp/server.html ]; then
echo "Cannot get index.html from web server (aborted)" >&2
return 2
fi
bundle exec jammit
}
function chk_service
{
port=${1:?Missing port}
case $OS in
*[Bb][Ss][Dd]*|Darwin)
## checks ipv[46]
netstat -anL | awk '{print $2}' | grep "\.$1$"
;;
*)
# Is someone listening on the ports already? (ipv4 only test ?)
netstat -nl | grep '[^:]:'$port'[ \t]'
;;
esac
}
function redis_config
# Create/update the local redis.conf file from /etc master
{
if [ ! -w config ]; then
# read-only installation, should be OK
return
fi
if [ -r "/etc/redis.conf" ]; then
redis_conf="/etc/redis.conf"
elif [ -r "/etc/redis/redis.conf" ]; then
redis_conf="/etc/redis/redis.conf"
else
echo <<- EOM
Don't know how to configure redis for this platform. Copy
the configuration file redis.conf to the config directory
and patch it manually. In particular, don't daemonize.
EOM
return
fi
if [ config/redis.cont -nt $redis_conf ]
then
return
fi
cp $redis_conf config/redis.conf
sed -i -e '/^[^#]*daemonize/s/yes/no/' \
-e '/^[^#]*logfile/s|.*|logfile /var/log/diaspora/redis.log|' \
config/redis.conf
}
THIN_PORT=$(./script/get_env.sh 'pod_uri.port')
SOCKET_PORT=$(./script/get_env.sh 'socket_port')
# Is someone listening on the ports already? (ipv4 only test ?)
services=$( chk_service $THIN_PORT )
if [ -n "$services" ]; then
echo "Error: thin port $THIN_PORT is already in use. Exiting" >&2
echo " $services"
exit 64
fi
services=$( chk_service $SOCKET_PORT )
if [ -n "$services" ]; then
echo "Error: websocket port $SOCKET_PORT is already in use. Exiting" >&2
echo " $services"
exit 64
fi
# See http://bugs.joindiaspora.com/issues/722
services=$( chk_service 5379 )
if [ -n "$services" ]; then
echo "Error: Someone (another redis server?) is using redis port 5379" >&2
echo " $services"
exit 64
fi
# Check if Mongo is running
if ! ps ax | grep -v grep | grep mongod >/dev/null
then
echo "Error: Mongod not started. Exiting" >&2
exit 64
fi
redis_config
# Force AGPL
if [ -w public -a ! -e public/source.tar.gz ]; then
branch=$( git branch | awk '/^[*]/ {print $2}')
tar czf public/source.tar.gz `git ls-tree -r $branch | awk '{print $4}'`
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
# Precache jammit assets
if [[ -w public && ! -e 'public/stylesheets/application.css' ]]; then
if [ "$INIT_PUBLIC" != 'no' ]; then
echo "Making first-time server initialization."
init_public
fi
fi
if [ ! -e 'public/stylesheets/application.css' ]; then
echo 'Jammit precache error (now or at install)' >&2
exit 66
fi
mkdir -p -v log/thin/
bundle exec ruby ./script/websocket_server.rb&
redis-server config/redis.conf &>log/redis-console.log &
QUEUE=* bundle exec rake resque:work&
bundle exec thin start -p $THIN_PORT $@