Skip to content

Commit

Permalink
refactor script/server and associated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jhass committed Oct 19, 2012
1 parent b6d7bf8 commit f0ef4a7
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 134 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ app/assets/images/custom/*
# Configuration files
config/diaspora.yml
config/heroku.yml
config/script_server.yml
config/initializers/secret_token.rb
config/redis.conf
config/deploy_config.yml
Expand Down
14 changes: 13 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

## 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)

## Add Features
## Features

* Add password_confirmation field to registration page. [#3647](https://github.com/diaspora/diaspora/pull/3647)

Expand Down
8 changes: 2 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ gem 'rails', '3.2.8'

gem 'foreman', '0.59'

gem 'thin', '1.4.1', :require => false
gem 'unicorn', '4.3.1', :require => false

gem 'rails_autolink', '1.0.9'

# cross-origin resource sharing
Expand Down Expand Up @@ -43,11 +44,6 @@ group :production do # we don't install these on travis to speed up test runs

end

# configuration

group :heroku do
gem 'unicorn', '4.3.1', :require => false
end

# database

Expand Down
7 changes: 0 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ GEM
capybara (>= 1.1.2)
cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
daemons (1.1.9)
database_cleaner (0.8.0)
debugger (1.2.0)
columnize (>= 0.3.1)
Expand All @@ -124,7 +123,6 @@ GEM
warden (~> 1.2.1)
diff-lcs (1.1.3)
erubis (2.7.0)
eventmachine (0.12.10)
excon (0.16.2)
execjs (1.4.0)
multi_json (~> 1.0)
Expand Down Expand Up @@ -374,10 +372,6 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
subexec (0.2.2)
thin (1.4.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.16.0)
tilt (1.3.3)
timecop (0.5.1)
Expand Down Expand Up @@ -481,7 +475,6 @@ DEPENDENCIES
sass-rails (= 3.2.5)
selenium-webdriver (= 2.25.0)
spork (= 1.0.0rc3)
thin (= 1.4.1)
timecop (= 0.5.1)
twitter (= 2.0.2)
typhoeus (= 0.3.3)
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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
8 changes: 6 additions & 2 deletions config/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ defaults:
upload: false
host:
pubsub_server: 'https://pubsubhubbub.appspot.com/'
unicorn:
embed_resque_worker: false
server:
port: 3000
rails_environment: 'development'
db: 'mysql'
embed_resque_worker: false
resque_workers: 1
privacy:
jquery_cdn: true
google_analytics_key:
Expand Down
21 changes: 17 additions & 4 deletions config/diaspora.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,23 @@ configuration: ## Section
## You likely don't want to change this.
#pubsub_server: 'https://pubsubhubbub.appspot.com/'

unicorn: ## Section
## Embed a resque worker inside the unicorn process, useful for
## minimal Heroku setups
#embed_resque_worker: true
server: ## Section
## The port on which the appserver should listen
#port: 3000

## 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
privacy: ## Section
Expand Down
15 changes: 0 additions & 15 deletions config/script_server.yml.example

This file was deleted.

2 changes: 1 addition & 1 deletion config/unicorn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Resque.redis.client.disconnect
end

if AppConfig.environment.unicorn.embed_resque_worker?
if AppConfig.server.embed_resque_worker?
# Clean up Resque workers killed by previous deploys/restarts
Resque.workers.each { |w| w.unregister_worker }
@resque_pid ||= spawn('bundle exec rake resque:work QUEUES=*')
Expand Down
48 changes: 20 additions & 28 deletions script/get_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

unless ARGV.length >= 1
$stderr.puts "Usage: ./script/get_config.rb var=option | option [...]"
Process.exit(1)
end

require 'rubygems'
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
def self.root
@@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..")))
Expand All @@ -14,38 +24,20 @@ def self.root
def self.env
env = 'development'
env = ENV['RAILS_ENV'] if ENV.has_key?('RAILS_ENV')
env = ARGV[1] if ARGV.length == 2
env.downcase
end
end

require Rails.root.join("config/load_config")

if ARGV.length >= 1
setting_name = ARGV[0]
if Rails.env == 'script_server' # load from the special script_server_config.yml file
require 'yaml'
script_server_config_file = Rails.root.join('config', 'script_server.yml')
begin
print YAML.load_file(script_server_config_file)['script_server'][setting_name]
rescue
$stderr.puts "Setting '#{setting_name}' not found in file #{script_server_config_file}."
$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
ARGV.each do |arg|
var, setting_name = arg.split("=")
setting_name = var unless setting_name
setting = AppConfig.send(setting_name)
setting = setting.get if setting.is_a?(Configuration::Proxy)
if var != setting_name
puts "#{var}=#{setting}"
else
puts setting
end
else
$stderr.puts "Usage: ./script/get_config.rb option [section]"
$stderr.puts ""
$stderr.puts "section defaults to development"
Process.exit(1)
end
Loading

0 comments on commit f0ef4a7

Please sign in to comment.