Merge pull request #4117 from MrZYX/script_server
Refactor script/server
This commit is contained in:
commit
6bcac2a7ad
4 changed files with 106 additions and 70 deletions
|
|
@ -104,6 +104,7 @@ everything is set up.
|
||||||
* Add a configuration entry to set max-age header to Amazon S3 resources. [#4048](https://github.com/diaspora/diaspora/pull/4048)
|
* Add a configuration entry to set max-age header to Amazon S3 resources. [#4048](https://github.com/diaspora/diaspora/pull/4048)
|
||||||
* Load images via sprites [#4039](https://github.com/diaspora/diaspora/pull/4039)
|
* Load images via sprites [#4039](https://github.com/diaspora/diaspora/pull/4039)
|
||||||
* Delete unnecessary javascript views. [#4059](https://github.com/diaspora/diaspora/pull/4059)
|
* Delete unnecessary javascript views. [#4059](https://github.com/diaspora/diaspora/pull/4059)
|
||||||
|
* Cleanup of script/server
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ defaults:
|
||||||
database: 'mysql'
|
database: 'mysql'
|
||||||
unicorn_worker: 2
|
unicorn_worker: 2
|
||||||
embed_sidekiq_worker: false
|
embed_sidekiq_worker: false
|
||||||
|
sidekiq_workers: 1
|
||||||
privacy:
|
privacy:
|
||||||
jquery_cdn: true
|
jquery_cdn: true
|
||||||
google_analytics_key:
|
google_analytics_key:
|
||||||
|
|
|
||||||
|
|
@ -152,13 +152,18 @@ configuration: ## Section
|
||||||
## Valid choices are 'mysql' and 'postgres'
|
## Valid choices are 'mysql' and 'postgres'
|
||||||
#database: 'mysql'
|
#database: 'mysql'
|
||||||
|
|
||||||
## Number of unicorn worker processes, increase this if
|
## Number of Unicorn worker processes, increase this if
|
||||||
## you have many users
|
## you have many users
|
||||||
#unicorn_worker: 2
|
#unicorn_worker: 2
|
||||||
|
|
||||||
## Embed a Sidekiq worker inside the unicorn process, useful for
|
## Embed a Sidekiq worker inside the unicorn process, useful for
|
||||||
## minimal Heroku setups
|
## minimal Heroku setups
|
||||||
#embed_sidekiq_worker: true
|
#embed_sidekiq_worker: true
|
||||||
|
|
||||||
|
## Number of Sidekiq worker processes
|
||||||
|
## Most of the time you want to increase
|
||||||
|
## environment.sidekiq.concurrency instead!
|
||||||
|
#sidekiq_workers: 1
|
||||||
|
|
||||||
## Settings probably affecting the privacy of your users
|
## Settings probably affecting the privacy of your users
|
||||||
privacy: ## Section
|
privacy: ## Section
|
||||||
|
|
|
||||||
167
script/server
167
script/server
|
|
@ -3,54 +3,24 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
# ensure right directory
|
warning()
|
||||||
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
{
|
||||||
cd $(dirname $realpath)/..
|
echo "WARNING: $1" >&2
|
||||||
|
}
|
||||||
|
|
||||||
#Warn if legacy config exists
|
fatal()
|
||||||
if [ -e 'config/script_server.yml' ]; then
|
{
|
||||||
echo "WARNING: config/script_server.yml was merged into config/diaspora.yml. Please read the changelog!" >&2
|
echo "FATAL: $1" >&2
|
||||||
fi
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# Check if database.yml exists
|
on_failure()
|
||||||
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
|
if [ $? != 0 ]
|
||||||
exit 68
|
then
|
||||||
fi
|
fatal $1
|
||||||
|
fi
|
||||||
# Check if diaspora.yml exists
|
}
|
||||||
if [ ! -e 'config/diaspora.yml' ]; then
|
|
||||||
echo 'FATAL: config/diaspora.yml is missing! Copy over config/diaspora.yml.example to config/diaspora.yml and edit it properly!' >&2
|
|
||||||
exit 70
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Setup environment
|
|
||||||
if [ -z "$RAILS_ENV" ]; then
|
|
||||||
RAILS_ENV=$(bundle exec ruby ./script/get_config.rb server.rails_environment)
|
|
||||||
export RAILS_ENV
|
|
||||||
fi
|
|
||||||
|
|
||||||
os=`uname -s`
|
|
||||||
eval $(bundle exec ruby ./script/get_config.rb \
|
|
||||||
port=server.port \
|
|
||||||
db=server.database \
|
|
||||||
single_process_mode=environment.single_process_mode?
|
|
||||||
embed_sidekiq_worker=server.embed_sidekiq_worker
|
|
||||||
)
|
|
||||||
|
|
||||||
if [ -z "$DB" ]; then
|
|
||||||
DB=$db
|
|
||||||
export DB
|
|
||||||
fi
|
|
||||||
|
|
||||||
args="$@"
|
|
||||||
prev_arg=''
|
|
||||||
for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
|
|
||||||
do
|
|
||||||
[ "$prev_arg" = '-p' ] && port="$arg"
|
|
||||||
prev_arg="$arg"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Check if already running/port blocked
|
# Check if already running/port blocked
|
||||||
chk_service()
|
chk_service()
|
||||||
|
|
@ -69,43 +39,102 @@ chk_service()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
services=$( chk_service $port )
|
# ensure right directory
|
||||||
if [ -n "$services" ]; then
|
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
||||||
echo "FATAL: Error: port $port is already in use. Exiting" >&2
|
cd $(dirname $realpath)/..
|
||||||
echo " $services"
|
|
||||||
exit 64
|
#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
|
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
|
||||||
|
|
||||||
|
# Setup environment
|
||||||
|
if [ -z "$RAILS_ENV" ]
|
||||||
|
then
|
||||||
|
RAILS_ENV=$(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=$(bundle exec ruby ./script/get_config.rb \
|
||||||
|
port=server.port \
|
||||||
|
db=server.database \
|
||||||
|
single_process_mode=environment.single_process_mode? \
|
||||||
|
embed_sidekiq_worker=server.embed_sidekiq_worker \
|
||||||
|
workers=server.sidekiq_workers
|
||||||
|
)
|
||||||
|
on_failure "Couldn't parse config/diaspora.yml!"
|
||||||
|
eval "$vars"
|
||||||
|
|
||||||
|
if [ -z "$DB" ]
|
||||||
|
then
|
||||||
|
DB=$db
|
||||||
|
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
|
# Force AGPL
|
||||||
if [ -w public -a ! -e public/source.tar.gz ]; then
|
if [ -w "public" -a ! -e "public/source.tar.gz" ]
|
||||||
branch=$( git branch | awk '/^[*]/ {print $2}')
|
then
|
||||||
tar czf public/source.tar.gz `git ls-tree -r $branch | awk '{print $4}'`
|
branch=$(git branch | awk '/^[*]/ {print $2}')
|
||||||
|
tar czf public/source.tar.gz $(git ls-tree -r $branch | awk '{print $4}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e public/source.tar.gz ]; then
|
if [ ! -e "public/source.tar.gz" ]
|
||||||
echo "FATAL: Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
|
then
|
||||||
exit 65
|
fatal "Can't find, or even create, public/source.tar.gz."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if assets are precompiled
|
# Check if assets are precompiled
|
||||||
if [ "$RAILS_ENV" = 'production' ]; then
|
if [ "$RAILS_ENV" = "production" -a ! -e "public/assets/default.css" ]
|
||||||
if [ ! -e 'public/assets/default.css' ]; then
|
then
|
||||||
echo "FATAL: You're running in production mode without having assets precompiled." >&2
|
fatal <<MSG
|
||||||
echo "Now and after each update before you restart the application, run:" >&2
|
You're running in production mode without having assets precompiled.
|
||||||
echo "bundle exec rake assets:precompile" >&2
|
Now and after each update before you restart the application, run:
|
||||||
exit 71
|
bundle exec rake assets:precompile
|
||||||
fi
|
MSG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Start Diaspora
|
# Start Diaspora
|
||||||
echo -n "Starting Diaspora in $RAILS_ENV mode on port $port "
|
echo -n "Starting Diaspora in $RAILS_ENV mode on port $port "
|
||||||
if [ "$embed_sidekiq_worker" = "true" ]; then
|
if [ "$embed_sidekiq_worker" = "true" ]
|
||||||
echo "with a sidekiq worker embeded into unicorn."
|
then
|
||||||
elif [ "$single_process_mode" = "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."
|
echo "with job processing inside the request cycle."
|
||||||
|
workers=0
|
||||||
|
else
|
||||||
|
echo "with $workers Sidekiq worker(s)."
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
exec bundle exec foreman start -m "web=1,sidekiq=1" -p $port
|
exec bundle exec foreman start -m "web=1,sidekiq=$workers" -p $port
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue