207 lines
5.2 KiB
Bash
Executable file
207 lines
5.2 KiB
Bash
Executable file
#!/bin/sh
|
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
# licensed under the Affero General Public License version 3 or later. See
|
|
# the COPYRIGHT file.
|
|
|
|
warning()
|
|
{
|
|
echo "WARNING: $1" >&2
|
|
}
|
|
|
|
fatal()
|
|
{
|
|
echo "FATAL: $1" >&2
|
|
exit 1
|
|
}
|
|
|
|
on_failure()
|
|
{
|
|
if [ $? != 0 ]
|
|
then
|
|
fatal "$1"
|
|
fi
|
|
}
|
|
|
|
# Check if already running/port blocked
|
|
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
|
|
}
|
|
|
|
|
|
# ensure right directory
|
|
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
|
cd $(dirname $realpath)/..
|
|
|
|
#Warn if legacy config exists
|
|
if [ -e "config/script_server.yml" ]
|
|
then
|
|
warning "config/script_server.yml was merged into config/diaspora.yml. Please read the changelog!"
|
|
fi
|
|
|
|
# Check if database.yml exists
|
|
if [ ! -e "config/database.yml" ]
|
|
then
|
|
fatal "config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!"
|
|
fi
|
|
|
|
# Check if diaspora.yml exists
|
|
if [ ! -e "config/diaspora.yml" ]
|
|
then
|
|
fatal "config/diaspora.yml is missing! Copy over config/diaspora.yml.example to config/diaspora.yml and edit it properly!"
|
|
fi
|
|
|
|
command -v git > /dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
# Check if git merge is in progress
|
|
if [ -f .git/MERGE_MODE ]; then
|
|
fatal "A git merge is in progress!"
|
|
fi
|
|
|
|
# Check if detached head state
|
|
git_branch_name="$(git symbolic-ref HEAD 2>/dev/null)"
|
|
if [ -z "$git_branch_name" ];
|
|
then
|
|
warning "You are in detached HEAD state!"
|
|
fi
|
|
fi
|
|
|
|
# Do RVM checks if RVM is being used
|
|
command -v rvm > /dev/null 2>&1
|
|
if [ $? -eq 0 ]; then
|
|
rvm_gemset="$(rvm current | cut -d"@" -f2)"
|
|
project_gemset="$(cat .ruby-gemset | tr -d " \t\n\r")"
|
|
if [ "$rvm_gemset" != "$project_gemset" ]; then
|
|
warning "Project gemset is $project_gemset but you are using $rvm_gemset"
|
|
fi
|
|
fi
|
|
|
|
# Check if bundle is complete
|
|
if ! bundle check > /dev/null
|
|
then
|
|
fatal "Your bundle is not up to date, run the command \"bundle install\""
|
|
fi
|
|
|
|
# Setup environment
|
|
if [ -z "$RAILS_ENV" ]
|
|
then
|
|
RAILS_ENV=$(bin/bundle exec ruby ./script/get_config.rb server.rails_environment)
|
|
on_failure "Couldn't parse config/diaspora.yml!"
|
|
export RAILS_ENV
|
|
fi
|
|
|
|
|
|
os=$(uname -s)
|
|
vars=$(bin/bundle exec ruby ./script/get_config.rb \
|
|
port=server.port \
|
|
single_process_mode=environment.single_process_mode? \
|
|
embed_sidekiq_worker=server.embed_sidekiq_worker \
|
|
workers=server.sidekiq_workers \
|
|
chat=chat.enabled \
|
|
chat_server=chat.server.enabled \
|
|
chat_bosh_proxy=chat.server.bosh.proxy
|
|
)
|
|
on_failure "Couldn't parse config/diaspora.yml!"
|
|
eval "$vars"
|
|
|
|
if [ -n "$DB" ]
|
|
then
|
|
export DB
|
|
fi
|
|
|
|
args="$@"
|
|
for arg in $(echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
|
|
do
|
|
[ "$prev_arg" = '-p' ] && port="$arg"
|
|
prev_arg="$arg"
|
|
done
|
|
|
|
services=$(chk_service $port )
|
|
if [ -n "$services" ]
|
|
then
|
|
fatal "Port $port is already in use.\n\t$services"
|
|
fi
|
|
|
|
# Force AGPL
|
|
if [ -w "public" -a ! -e "public/source.tar.gz" ]
|
|
then
|
|
if command -v git > /dev/null 2>&1 && git rev-parse --is-inside-work-tree > /dev/null 2>&1
|
|
then
|
|
commit_sha=$(git rev-parse HEAD)
|
|
tar czf public/source.tar.gz $(git ls-tree -r $commit_sha | awk '{print $4}')
|
|
else
|
|
fatal "Can't generate public/source.tar.gz for you.
|
|
Please tar up a copy of your Diaspora installation and place it there."
|
|
fi
|
|
fi
|
|
|
|
if [ ! -e "public/source.tar.gz" ]
|
|
then
|
|
fatal "Can't find public/source.tar.gz"
|
|
fi
|
|
|
|
# Check if assets are precompiled
|
|
if [ "$RAILS_ENV" = "production" -a -z "$(find public/assets -maxdepth 1 -name 'home-*.css' -print -quit 2>/dev/null)" ]
|
|
then
|
|
fatal "You're running in production mode without having assets
|
|
precompiled. Now and after each update before you restart the
|
|
application, run:
|
|
bin/rake assets:precompile"
|
|
fi
|
|
|
|
# Check for old curl versions (see https://github.com/diaspora/diaspora/issues/4202)
|
|
if [ `curl -V | grep AsynchDNS | wc -l` -ne 1 ]
|
|
then
|
|
warning "
|
|
*****************************************************************
|
|
curl does not support async DNS, this can cause Sidekiq to crash!
|
|
Please update curl to version 7.32, see issue
|
|
https://github.com/diaspora/diaspora/issues/4202 for details
|
|
*****************************************************************
|
|
"
|
|
fi
|
|
|
|
vines=0
|
|
if [ "$chat" = "true" ] && [ "$chat_server" = "true" ]
|
|
then
|
|
vines=1
|
|
if [ "$chat_bosh_proxy" = "false" ]
|
|
then
|
|
warning "
|
|
*****************************************************************
|
|
You enabled the chat feature but haven't configured BOSH! That
|
|
could lead to mixed-content problems with the http clients. Please
|
|
think about editing your proxy configuration as described in:
|
|
|
|
diaspora.yml.example
|
|
*****************************************************************
|
|
"
|
|
fi
|
|
fi
|
|
|
|
# Start Diaspora
|
|
printf "Starting Diaspora in $RAILS_ENV mode on port $port "
|
|
if [ "$embed_sidekiq_worker" = "true" ]
|
|
then
|
|
echo "with a Sidekiq worker embedded into Unicorn."
|
|
workers=0
|
|
elif [ "$single_process_mode" = "true" ]
|
|
then
|
|
echo "with job processing inside the request cycle."
|
|
workers=0
|
|
else
|
|
echo "with $workers Sidekiq worker(s)."
|
|
fi
|
|
echo ""
|
|
|
|
exec bin/bundle exec foreman start -m "xmpp=$vines,web=1,sidekiq=$workers" -p $port
|