refactor script/server and associated stuff
This commit is contained in:
parent
b6d7bf81f7
commit
f0ef4a764e
11 changed files with 131 additions and 133 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -6,7 +6,6 @@ app/assets/images/custom/*
|
||||||
# Configuration files
|
# Configuration files
|
||||||
config/diaspora.yml
|
config/diaspora.yml
|
||||||
config/heroku.yml
|
config/heroku.yml
|
||||||
config/script_server.yml
|
|
||||||
config/initializers/secret_token.rb
|
config/initializers/secret_token.rb
|
||||||
config/redis.conf
|
config/redis.conf
|
||||||
config/deploy_config.yml
|
config/deploy_config.yml
|
||||||
|
|
|
||||||
14
Changelog.md
14
Changelog.md
|
|
@ -2,9 +2,21 @@
|
||||||
|
|
||||||
## Refactor
|
## Refactor
|
||||||
|
|
||||||
|
### script/server
|
||||||
|
|
||||||
|
* Uses foreman now
|
||||||
|
* Reduce startup time by reducing calls to `script/get_config.rb`
|
||||||
|
* `config/script_server.yml` is removed and replaced by the `server` section in `config/diaspora.yml`
|
||||||
|
Have a look at the updated example!
|
||||||
|
* Thin is dropped in favour of unicorn
|
||||||
|
* Already set versions of `RAILS_ENV` and `DB` are now prefered over those set in `config/diaspora.yml`
|
||||||
|
* **Heroku setups:** `ENVIRONMENT_UNICORN_EMBED_RESQUE_WORKER` got renamed to `SERVER_EMBED_RESQUE_WORKER`
|
||||||
|
|
||||||
|
### Other
|
||||||
|
|
||||||
* MessagesController. [#3657](https://github.com/diaspora/diaspora/pull/3657)
|
* MessagesController. [#3657](https://github.com/diaspora/diaspora/pull/3657)
|
||||||
|
|
||||||
## Add Features
|
## Features
|
||||||
|
|
||||||
* Add password_confirmation field to registration page. [#3647](https://github.com/diaspora/diaspora/pull/3647)
|
* Add password_confirmation field to registration page. [#3647](https://github.com/diaspora/diaspora/pull/3647)
|
||||||
|
|
||||||
|
|
|
||||||
8
Gemfile
8
Gemfile
|
|
@ -6,7 +6,8 @@ gem 'rails', '3.2.8'
|
||||||
|
|
||||||
gem 'foreman', '0.59'
|
gem 'foreman', '0.59'
|
||||||
|
|
||||||
gem 'thin', '1.4.1', :require => false
|
gem 'unicorn', '4.3.1', :require => false
|
||||||
|
|
||||||
gem 'rails_autolink', '1.0.9'
|
gem 'rails_autolink', '1.0.9'
|
||||||
|
|
||||||
# cross-origin resource sharing
|
# cross-origin resource sharing
|
||||||
|
|
@ -43,11 +44,6 @@ group :production do # we don't install these on travis to speed up test runs
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# configuration
|
|
||||||
|
|
||||||
group :heroku do
|
|
||||||
gem 'unicorn', '4.3.1', :require => false
|
|
||||||
end
|
|
||||||
|
|
||||||
# database
|
# database
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,6 @@ GEM
|
||||||
capybara (>= 1.1.2)
|
capybara (>= 1.1.2)
|
||||||
cucumber (>= 1.1.8)
|
cucumber (>= 1.1.8)
|
||||||
nokogiri (>= 1.5.0)
|
nokogiri (>= 1.5.0)
|
||||||
daemons (1.1.9)
|
|
||||||
database_cleaner (0.8.0)
|
database_cleaner (0.8.0)
|
||||||
debugger (1.2.0)
|
debugger (1.2.0)
|
||||||
columnize (>= 0.3.1)
|
columnize (>= 0.3.1)
|
||||||
|
|
@ -124,7 +123,6 @@ GEM
|
||||||
warden (~> 1.2.1)
|
warden (~> 1.2.1)
|
||||||
diff-lcs (1.1.3)
|
diff-lcs (1.1.3)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
eventmachine (0.12.10)
|
|
||||||
excon (0.16.2)
|
excon (0.16.2)
|
||||||
execjs (1.4.0)
|
execjs (1.4.0)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
|
|
@ -374,10 +372,6 @@ GEM
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
subexec (0.2.2)
|
subexec (0.2.2)
|
||||||
thin (1.4.1)
|
|
||||||
daemons (>= 1.0.9)
|
|
||||||
eventmachine (>= 0.12.6)
|
|
||||||
rack (>= 1.0.0)
|
|
||||||
thor (0.16.0)
|
thor (0.16.0)
|
||||||
tilt (1.3.3)
|
tilt (1.3.3)
|
||||||
timecop (0.5.1)
|
timecop (0.5.1)
|
||||||
|
|
@ -481,7 +475,6 @@ DEPENDENCIES
|
||||||
sass-rails (= 3.2.5)
|
sass-rails (= 3.2.5)
|
||||||
selenium-webdriver (= 2.25.0)
|
selenium-webdriver (= 2.25.0)
|
||||||
spork (= 1.0.0rc3)
|
spork (= 1.0.0rc3)
|
||||||
thin (= 1.4.1)
|
|
||||||
timecop (= 0.5.1)
|
timecop (= 0.5.1)
|
||||||
twitter (= 2.0.2)
|
twitter (= 2.0.2)
|
||||||
typhoeus (= 0.3.3)
|
typhoeus (= 0.3.3)
|
||||||
|
|
|
||||||
2
Procfile
2
Procfile
|
|
@ -1,2 +1,2 @@
|
||||||
web: bundle exec unicorn -c config/unicorn.rb -p $PORT
|
web: bundle exec unicorn -c config/unicorn.rb -p $PORT
|
||||||
worker: env QUEUE=* bundle exec rake resque:work
|
worker: env QUEUE=* bundle exec rake resque:work
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,12 @@ defaults:
|
||||||
upload: false
|
upload: false
|
||||||
host:
|
host:
|
||||||
pubsub_server: 'https://pubsubhubbub.appspot.com/'
|
pubsub_server: 'https://pubsubhubbub.appspot.com/'
|
||||||
unicorn:
|
server:
|
||||||
embed_resque_worker: false
|
port: 3000
|
||||||
|
rails_environment: 'development'
|
||||||
|
db: 'mysql'
|
||||||
|
embed_resque_worker: false
|
||||||
|
resque_workers: 1
|
||||||
privacy:
|
privacy:
|
||||||
jquery_cdn: true
|
jquery_cdn: true
|
||||||
google_analytics_key:
|
google_analytics_key:
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,23 @@ configuration: ## Section
|
||||||
## You likely don't want to change this.
|
## You likely don't want to change this.
|
||||||
#pubsub_server: 'https://pubsubhubbub.appspot.com/'
|
#pubsub_server: 'https://pubsubhubbub.appspot.com/'
|
||||||
|
|
||||||
unicorn: ## Section
|
server: ## Section
|
||||||
## Embed a resque worker inside the unicorn process, useful for
|
## The port on which the appserver should listen
|
||||||
## minimal Heroku setups
|
#port: 3000
|
||||||
#embed_resque_worker: true
|
|
||||||
|
## The environment in which the server should be started by default.
|
||||||
|
#rails_environment: 'production'
|
||||||
|
|
||||||
|
## The database type the server should use by default.
|
||||||
|
## Valid choices are 'mysql' and 'postgres'
|
||||||
|
#database: 'mysql'
|
||||||
|
|
||||||
|
## Embed a resque worker inside the unicorn process, useful for
|
||||||
|
## minimal Heroku setups
|
||||||
|
#embed_resque_worker: true
|
||||||
|
|
||||||
|
## Number of resque workers to start
|
||||||
|
#resque_workers: 1
|
||||||
|
|
||||||
## Settings probably affecting the privacy of your users
|
## Settings probably affecting the privacy of your users
|
||||||
privacy: ## Section
|
privacy: ## Section
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
script_server:
|
|
||||||
# Choose database. Currently supported: mysql, postgres
|
|
||||||
db: "mysql"
|
|
||||||
|
|
||||||
# Enable thin as application server
|
|
||||||
enable_thin: true
|
|
||||||
|
|
||||||
# Port on which thin should listen
|
|
||||||
thin_port: 3000
|
|
||||||
|
|
||||||
# Customize thin's startup
|
|
||||||
default_thin_args: "-p $THIN_PORT -e $RAILS_ENV"
|
|
||||||
|
|
||||||
# Possibilities are development, production
|
|
||||||
rails_env: "development"
|
|
||||||
|
|
@ -32,7 +32,7 @@ before_fork do |server, worker|
|
||||||
Resque.redis.client.disconnect
|
Resque.redis.client.disconnect
|
||||||
end
|
end
|
||||||
|
|
||||||
if AppConfig.environment.unicorn.embed_resque_worker?
|
if AppConfig.server.embed_resque_worker?
|
||||||
# Clean up Resque workers killed by previous deploys/restarts
|
# Clean up Resque workers killed by previous deploys/restarts
|
||||||
Resque.workers.each { |w| w.unregister_worker }
|
Resque.workers.each { |w| w.unregister_worker }
|
||||||
@resque_pid ||= spawn('bundle exec rake resque:work QUEUES=*')
|
@resque_pid ||= spawn('bundle exec rake resque:work QUEUES=*')
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,19 @@
|
||||||
# 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.
|
||||||
|
|
||||||
|
unless ARGV.length >= 1
|
||||||
|
$stderr.puts "Usage: ./script/get_config.rb var=option | option [...]"
|
||||||
|
Process.exit(1)
|
||||||
|
end
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
||||||
|
require 'active_support/core_ext/class/attribute_accessors'
|
||||||
|
require 'active_support/core_ext/object/blank'
|
||||||
|
require 'active_support/core_ext/module/delegation'
|
||||||
|
require 'active_support/core_ext/module/method_names'
|
||||||
|
|
||||||
class Rails
|
class Rails
|
||||||
def self.root
|
def self.root
|
||||||
@@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..")))
|
@@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..")))
|
||||||
|
|
@ -14,38 +24,20 @@ class Rails
|
||||||
def self.env
|
def self.env
|
||||||
env = 'development'
|
env = 'development'
|
||||||
env = ENV['RAILS_ENV'] if ENV.has_key?('RAILS_ENV')
|
env = ENV['RAILS_ENV'] if ENV.has_key?('RAILS_ENV')
|
||||||
env = ARGV[1] if ARGV.length == 2
|
|
||||||
env.downcase
|
env.downcase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require Rails.root.join("config/load_config")
|
||||||
|
|
||||||
if ARGV.length >= 1
|
ARGV.each do |arg|
|
||||||
setting_name = ARGV[0]
|
var, setting_name = arg.split("=")
|
||||||
if Rails.env == 'script_server' # load from the special script_server_config.yml file
|
setting_name = var unless setting_name
|
||||||
require 'yaml'
|
setting = AppConfig.send(setting_name)
|
||||||
script_server_config_file = Rails.root.join('config', 'script_server.yml')
|
setting = setting.get if setting.is_a?(Configuration::Proxy)
|
||||||
begin
|
if var != setting_name
|
||||||
print YAML.load_file(script_server_config_file)['script_server'][setting_name]
|
puts "#{var}=#{setting}"
|
||||||
rescue
|
else
|
||||||
$stderr.puts "Setting '#{setting_name}' not found in file #{script_server_config_file}."
|
puts setting
|
||||||
$stderr.puts "Does that file exist? If not, copy it from #{File.basename(script_server_config_file)}.example in the same directory and run this script again."
|
|
||||||
Process.exit(1)
|
|
||||||
end
|
|
||||||
else # load from the general diaspora settings file
|
|
||||||
require 'active_support/core_ext/class/attribute_accessors'
|
|
||||||
require 'active_support/core_ext/object/blank'
|
|
||||||
require 'active_support/core_ext/module/delegation'
|
|
||||||
require 'active_support/core_ext/module/method_names'
|
|
||||||
require Rails.root.join("config/load_config")
|
|
||||||
|
|
||||||
setting = AppConfig.send(setting_name)
|
|
||||||
setting = setting.get if setting.is_a?(Configuration::Proxy)
|
|
||||||
print setting
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
$stderr.puts "Usage: ./script/get_config.rb option [section]"
|
|
||||||
$stderr.puts ""
|
|
||||||
$stderr.puts "section defaults to development"
|
|
||||||
Process.exit(1)
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
138
script/server
138
script/server
|
|
@ -2,111 +2,115 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
# 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.
|
||||||
#
|
|
||||||
# This script is meant for running a small server in production. It starts the Diaspora
|
|
||||||
# server, redis, and resque. To run a server locally for development, use foreman instead:
|
|
||||||
# foreman start
|
|
||||||
#
|
|
||||||
|
|
||||||
# ensure right directory
|
# ensure right directory
|
||||||
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
realpath=$( ruby -e "puts File.expand_path(\"$0\")")
|
||||||
cd $(dirname $realpath)/..
|
cd $(dirname $realpath)/..
|
||||||
|
|
||||||
# Check if script_server.yml exists
|
#Warn if legacy config exists
|
||||||
if [ ! -e 'config/script_server.yml' ]; then
|
if [ -e 'config/script_server.yml' ]; then
|
||||||
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
|
echo "WARNING: config/script_server.yml was merged into config/diaspora.yml. Please read the changelog!" >&2
|
||||||
exit 69
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Check if database.yml exists
|
# Check if database.yml exists
|
||||||
if [ ! -e 'config/database.yml' ]; then
|
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
|
echo 'FATAL: config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!' >&2
|
||||||
exit 68
|
exit 68
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if diaspora.yml exists
|
||||||
# Check if application.yml exists
|
|
||||||
if [ ! -e 'config/diaspora.yml' ]; then
|
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
|
echo 'FATAL: config/diaspora.yml is missing! Copy over config/diaspora.yml.example to config/diaspora.yml and edit it properly!' >&2
|
||||||
exit 70
|
exit 70
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Setup environment
|
# Setup environment
|
||||||
OS=`uname -s`
|
if [ -z "$RAILS_ENV" ]; then
|
||||||
export RAILS_ENV=$(bundle exec ruby ./script/get_config.rb rails_env script_server)
|
export RAILS_ENV=$(bundle exec ruby ./script/get_config.rb server.rails_environment)
|
||||||
export DB=$(bundle exec ruby ./script/get_config.rb db script_server)
|
fi
|
||||||
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)\""
|
|
||||||
|
|
||||||
# Backward compatibillity, overide default settings
|
os=`uname -s`
|
||||||
[ -e config/server.sh ] && source config/server.sh
|
eval $(bundle exec ruby ./script/get_config.rb \
|
||||||
|
port=server.port \
|
||||||
|
db=server.db \
|
||||||
|
workers=server.resque_workers \
|
||||||
|
single_process_mode=environment.single_process_mode?
|
||||||
|
embed_resque_worker=server.embed_resque_worker
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ -z "$DB" ]; then
|
||||||
|
export DB=$db
|
||||||
|
fi
|
||||||
|
|
||||||
function chk_service
|
if [ "$single_process_mode" = "true" -o "$embed_resque_worker" = "true" ]; then
|
||||||
{
|
workers=0
|
||||||
port=${1:?Missing port}
|
fi
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
args="$@"
|
||||||
# Scan for -p, find out what port thin is about to use.
|
|
||||||
args="$DEFAULT_THIN_ARGS $@"
|
|
||||||
prev_arg=''
|
prev_arg=''
|
||||||
for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
|
for arg in $( echo $args | awk '{ for (i = 1; i <= NF; i++) print $i}')
|
||||||
do
|
do
|
||||||
[ "$prev_arg" = '-p' ] && THIN_PORT="$arg"
|
[ "$prev_arg" = '-p' ] && port="$arg"
|
||||||
prev_arg="$arg"
|
prev_arg="$arg"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check if already running/port blocked
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
# Is someone listening on the ports already? (ipv4 only test ?)
|
|
||||||
services=$( chk_service $THIN_PORT )
|
services=$( chk_service $port )
|
||||||
if [ -n "$services" ]; then
|
if [ -n "$services" ]; then
|
||||||
echo "FATAL: Error: thin port $THIN_PORT is already in use. Exiting" >&2
|
echo "FATAL: Error: port $port is already in use. Exiting" >&2
|
||||||
echo " $services"
|
echo " $services"
|
||||||
exit 64
|
exit 64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Force AGPL
|
# Force AGPL
|
||||||
if [ -w public -a ! -e public/source.tar.gz ]; then
|
if [ -w public -a ! -e public/source.tar.gz ]; then
|
||||||
branch=$( git branch | awk '/^[*]/ {print $2}')
|
branch=$( git branch | awk '/^[*]/ {print $2}')
|
||||||
tar czf public/source.tar.gz `git ls-tree -r $branch | awk '{print $4}'`
|
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 ]; then
|
||||||
echo "FATAL: Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
|
echo "FATAL: Error: Can't find, or even create, public/source.tar.gz. Exiting" >&2
|
||||||
exit 65
|
exit 65
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if assets are precompiled
|
||||||
if [ ! -e 'public/assets/default.css' ]; then
|
if [ "$RAILS_ENV" == 'production' ]; then
|
||||||
if [ "$RAILS_ENV" == 'production' ]; then
|
if [ ! -e 'public/assets/default.css' ]; then
|
||||||
echo "FATAL: You're running in production mode without having assets precompiled." >&2
|
echo "FATAL: You're running in production mode without having assets precompiled." >&2
|
||||||
echo "Now and after each git pull before you restart the application, run:" >&2
|
echo "Now and after each update before you restart the application, run:" >&2
|
||||||
echo "bundle exec rake assets:precompile" >&2
|
echo "bundle exec rake assets:precompile" >&2
|
||||||
exit 71
|
exit 71
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Start Diaspora
|
# Start Diaspora
|
||||||
|
echo -n "Starting Diaspora in $RAILS_ENV mode on port $port "
|
||||||
if [ "$(bundle exec ruby ./script/get_config.rb 'environment.single_process_mode?')" != "true" ]; then
|
if [ "$embed_resque_worker" = "true" ]; then
|
||||||
QUEUE=* bundle exec rake resque:work&
|
echo "with a resque worker embeded into unicorn."
|
||||||
|
elif [ "$single_process_mode" = "true" ]; then
|
||||||
|
echo "with job processing inside the request cycle."
|
||||||
|
else
|
||||||
|
echo "with $workers resque workers."
|
||||||
fi
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
if [ "$(./script/get_config.rb enable_thin script_server)" = "true" ]; then
|
bundle exec foreman start -c "web=1,worker=$workers" -p $port
|
||||||
bundle exec thin start $args
|
|
||||||
fi
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue