Newer
Older
# Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
# Start diaspora websocket and main services
#
# ensure right directory
cd $(dirname $(readlink -e $0))/..
# Check if script_server.yml exists
if [ ! -e 'config/script_server.yml' ]; then
Jonne Hass
a validé
echo "INFO: config/script_server_config.yml has been renamed to config/script_server.yml" >&2
echo 'FATAL: config/script_server.yml is missing! Copy over config/script_server.yml.example to config/script_server.yml and edit it properly!' >&2
exit 69
fi
# Check if database.yml exists
if [ ! -e 'config/database.yml' ]; then
echo 'FATAL: config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!' >&2
exit 68
fi
# Check if application.yml exists
if [ ! -e 'config/application.yml' ]; then
echo 'FATAL: config/application.yml is missing! Copy over config/application.yml.example to config/application.yml and edit it properly!' >&2
exit 70
fi
# Setup environment
OS=`uname -s`
export RAILS_ENV=$(bundle exec ruby ./script/get_config.rb rails_env script_server)
export DB=$(bundle exec ruby ./script/get_config.rb db script_server)
THIN_PORT=$(bundle exec ruby ./script/get_config.rb thin_port script_server)
eval "DEFAULT_THIN_ARGS=\"$(bundle exec ruby ./script/get_config.rb default_thin_args script_server)\""
SOCKET_PORT=$(bundle exec ruby ./script/get_config.rb socket_port $RAILS_ENV)
# Backward compatibillity, overide default settings
[ -e config/server.sh ] && source config/server.sh
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"
elif [ -r "/opt/local/etc/redis.conf" ]; then
# MacPorts location
redis_conf="/opt/local/etc/redis.conf"
elif [ -r "/usr/local/etc/redis.conf" ]; then
redis_conf="/usr/local/etc/redis.conf"
elif [ -r "/usr/local/etc/redis/redis.conf" ]; then
redis_conf="/usr/local/etc/redis/redis.conf"
echo "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." >&2
if [ config/redis.conf -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
# Scan for -p, find out what port thin is about to use.
args="$DEFAULT_THIN_ARGS $@"
prev_arg=''
for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
do
[ "$prev_arg" = '-p' ] && THIN_PORT="$arg"
prev_arg="$arg"
# Is someone listening on the ports already? (ipv4 only test ?)
if [ -n "$services" ]; then
echo "FATAL: Error: thin port $THIN_PORT is already in use. Exiting" >&2
echo " $services"
exit 64
fi
if [ -n "$services" ]; then
echo "FATAL: Error: websocket port $SOCKET_PORT is already in use. Exiting" >&2
echo " $services"
# See http://bugs.joindiaspora.com/issues/722
services=$( chk_service 5379 )
if [ -n "$services" ]; then
echo "FATAL: Error: Someone (another redis server?) is using redis port 5379" >&2
echo " $services"
exit 64
fi
# 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 "FATAL: Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
exit 65
fi
if [ ! -e 'public/assets/default.css' ]; then
if [ "$RAILS_ENV" == 'production' ]; then
echo "INFO: If you want further performance improvements," >&2
echo "after the first request to the page after each git pull, run:" >&2
echo "bundle exec jammit" >&2
if [ "$(bundle exec ruby ./script/get_config.rb 'single_process_mode?')" != "true" ]; then
redis-server config/redis.conf &>log/redis-console.log &
QUEUE=* bundle exec rake resque:work&
danielgrippi
a validé
bundle exec ruby ./script/websocket_server.rb&
MrZYX
a validé
if [ "$(./script/get_config.rb enable_thin script_server)" = "true" ]; then
MrZYX
a validé
bundle exec thin start $args
fi