Commit b71625c8b58f573e23342fb1c32d9e6f2bfde5e1
Exists in
master
and in
21 other branches
Merge branch 'master' of gitlab.com:noosfero/noosfero
Showing
21 changed files
with
100 additions
and
106 deletions
Show diff stats
Gemfile
... | ... | @@ -10,7 +10,7 @@ gem 'RedCloth', '~> 4.2.9' |
10 | 10 | gem 'will_paginate', '~> 3.0.3' |
11 | 11 | gem 'ruby-feedparser', '~> 0.7' |
12 | 12 | gem 'daemons', '~> 1.1.5' |
13 | -gem 'thin', '~> 1.3.1' | |
13 | +gem 'unicorn', '~> 4.8' | |
14 | 14 | gem 'nokogiri', '~> 1.5.5' |
15 | 15 | gem 'rake', :require => false |
16 | 16 | gem 'rest-client', '~> 1.6.7' | ... | ... |
config.ru
... | ... | @@ -2,10 +2,6 @@ |
2 | 2 | |
3 | 3 | require ::File.expand_path('../config/environment', __FILE__) |
4 | 4 | |
5 | -#use Rails::Rack::LogTailer | |
6 | -#use Rails::Rack::Static | |
7 | -#run ActionController::Dispatcher.new | |
8 | - | |
9 | 5 | use Rack::Cors do |
10 | 6 | allow do |
11 | 7 | origins '*' |
... | ... | @@ -14,7 +10,13 @@ use Rack::Cors do |
14 | 10 | end |
15 | 11 | |
16 | 12 | rails_app = Rack::Builder.new do |
17 | - run Noosfero::Application | |
13 | + if ENV['RAILS_RELATIVE_URL_ROOT'] | |
14 | + map ENV['RAILS_RELATIVE_URL_ROOT'] do | |
15 | + run Noosfero::Application | |
16 | + end | |
17 | + else | |
18 | + run Noosfero::Application | |
19 | + end | |
18 | 20 | end |
19 | 21 | |
20 | 22 | run Rack::Cascade.new([ | ... | ... |
config/thin.yml.dist
debian/apache2/conf.d/noosfero-cluster.conf
debian/apache2/virtualhost.conf
... | ... | @@ -15,7 +15,11 @@ RewriteRule ^/$ /index.html [QSA] |
15 | 15 | RewriteRule ^([^.]+)$ $1.html [QSA] |
16 | 16 | |
17 | 17 | RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f |
18 | -RewriteRule ^.*$ balancer://noosfero%{REQUEST_URI} [P,QSA,L] | |
18 | +RewriteRule ^.*$ http://127.0.0.1:50000%{REQUEST_URI} [P,QSA,L] | |
19 | +<Proxy http://127.0.0.1:50000> | |
20 | + Order Allow,Deny | |
21 | + Allow from All | |
22 | +</Proxy> | |
19 | 23 | |
20 | 24 | ErrorDocument 503 /503.html |
21 | 25 | ... | ... |
debian/control
... | ... | @@ -70,7 +70,7 @@ Depends: adduser, |
70 | 70 | ruby-whenever, |
71 | 71 | ruby-will-paginate (>= 2.3.12-1~), |
72 | 72 | tango-icon-theme, |
73 | - thin, | |
73 | + unicorn (>= 4.8), | |
74 | 74 | ${misc:Depends} |
75 | 75 | Recommends: postgresql, postgresql-client |
76 | 76 | Description: free web-based platform for social networks | ... | ... |
debian/noosfero-apache.install
debian/noosfero.install
... | ... | @@ -19,7 +19,7 @@ debian/noosfero-check-dbconfig usr/sbin |
19 | 19 | debian/noosfero-console usr/sbin |
20 | 20 | debian/noosfero-runner usr/sbin |
21 | 21 | debian/noosfero.yml etc/noosfero |
22 | -debian/thin.yml etc/noosfero | |
22 | +debian/unicorn.rb etc/noosfero | |
23 | 23 | doc usr/share/noosfero |
24 | 24 | doc/noosfero usr/share/noosfero/doc |
25 | 25 | etc/init.d/noosfero etc/init.d | ... | ... |
debian/noosfero.links
1 | 1 | var/tmp/noosfero usr/share/noosfero/tmp |
2 | 2 | var/log/noosfero usr/share/noosfero/log |
3 | 3 | etc/noosfero/database.yml usr/share/noosfero/config/database.yml |
4 | -etc/noosfero/thin.yml usr/share/noosfero/config/thin.yml | |
4 | +etc/noosfero/unicorn.rb usr/share/noosfero/config/unicorn.rb | |
5 | 5 | etc/noosfero/plugins usr/share/noosfero/config/plugins |
6 | 6 | etc/noosfero/noosfero.yml usr/share/noosfero/config/noosfero.yml |
7 | 7 | etc/noosfero/local.rb usr/share/noosfero/config/local.rb | ... | ... |
debian/noosfero.postinst
... | ... | @@ -10,23 +10,23 @@ makedir() { |
10 | 10 | } |
11 | 11 | |
12 | 12 | |
13 | -# migrate mongrel configuration to thin | |
14 | -mongrel_config=/etc/noosfero/mongrel_cluster.yml | |
13 | +# migrate thin configuration to unicorn | |
14 | +unicorn_config=/etc/noosfero/unicorn.rb | |
15 | 15 | thin_config=/etc/noosfero/thin.yml |
16 | -mongrel_orig_sha1=602c642c03f79349969c08330112a6f29d4c32aa | |
17 | -if [ -r $mongrel_config ]; then | |
18 | - mongrel_sha1=$(sha1sum $mongrel_config | awk '{print $1}') | |
19 | - if [ "$mongrel_sha1" != "$mongrel_orig_sha1" ]; then | |
20 | - port=$(awk '{ if ($1 == "port:") { print($2) } }' $mongrel_config) | |
21 | - servers=$(awk '{ if ($1 == "servers:") { print($2) } }' $mongrel_config) | |
16 | +thin_orig_sha1=47cee6728a7896a13f4d66544086ab88b02e89a7 | |
17 | +if [ -r $thin_config ]; then | |
18 | + thin_sha1=$(sha1sum $thin_config | awk '{print $1}') | |
19 | + if [ "$thin_sha1" != "$thin_orig_sha1" ]; then | |
20 | + port=$(awk '{ if ($1 == "port:") { print($2) } }' $thin_config) | |
21 | + servers=$(awk '{ if ($1 == "servers:") { print($2) } }' $thin_config) | |
22 | 22 | if test -n "$port" && test "$port" -ne 50000 || test -n "$servers" && test "$servers" -ne 1 ; then |
23 | - # mongrel configuration was changed; update thin configuration | |
23 | + # thin configuration was changed; update unicorn configuration | |
24 | 24 | # accordingly |
25 | - sed -i -e "s/port: .*/port: $port/" $thin_config | |
26 | - sed -i -e "s/servers: .*/servers: $servers/" $thin_config | |
25 | + sed -i -e "s/listen.*/listen '127.0.0.1:$port'/" $unicorn_config | |
26 | + sed -i -e "s/worker_processes.*/worker_processes $servers/" $unicorn_config | |
27 | 27 | fi |
28 | 28 | fi |
29 | - mv $mongrel_config $mongrel_config.bak | |
29 | + mv $thin_config $thin_config.bak | |
30 | 30 | fi |
31 | 31 | |
32 | 32 | # create user noosfero in a portable way, while creating the log directory. | ... | ... |
debian/thin.yml
debian/update-noosfero-apache
... | ... | @@ -2,20 +2,9 @@ |
2 | 2 | |
3 | 3 | set -e |
4 | 4 | |
5 | -# automatically update configuration, but if package noosfero is also installed | |
5 | +# automatically update configuration, but only if package noosfero is also | |
6 | +# installed | |
6 | 7 | if test -x /usr/share/noosfero/script/apacheconf; then |
7 | - datadir="/etc/noosfero/apache" | |
8 | - mongrel_file="$datadir/mongrel.conf" | |
9 | - cluster_file="$datadir/cluster.conf" | |
10 | - if test -e "$cluster_file"; then | |
11 | - echo "Overwriting $cluster_file ..." | |
12 | - fi | |
13 | - /usr/share/noosfero/script/apacheconf thin > "$cluster_file" | |
14 | - if test -e "$mongrel_file"; then | |
15 | - echo "Moving existing $mongrel_file away ..." | |
16 | - mv "$mongrel_file" "$mongrel_file".bak | |
17 | - (cd $datadir && ln -sf cluster.conf mongrel.conf) | |
18 | - fi | |
19 | 8 | |
20 | 9 | apache_site='/etc/apache2/sites-available/noosfero' |
21 | 10 | if ! test -e "$apache_site"; then | ... | ... |
gitignore.example
... | ... | @@ -0,0 +1,20 @@ |
1 | +# our defaults | |
2 | +listen "0.0.0.0:3000" | |
3 | +pid 'tmp/pids/unicorn.pid' | |
4 | + | |
5 | +preload_app true | |
6 | +GC.respond_to?(:copy_on_write_friendly=) and | |
7 | + GC.copy_on_write_friendly = true | |
8 | + | |
9 | +before_fork do |server, worker| | |
10 | + ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base) | |
11 | +end | |
12 | + | |
13 | +after_fork do |server, worker| | |
14 | + ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base) | |
15 | +end | |
16 | + | |
17 | +# load local configuration file, if it exists | |
18 | +config = File.join(File.dirname(__FILE__), '../../config/unicorn.rb') | |
19 | +instance_eval(File.read(config), config) if File.exists?(config) | |
20 | + | ... | ... |
script/apacheconf
1 | 1 | #!/usr/bin/env ruby |
2 | 2 | |
3 | -def mongrel_thin(config_file) | |
4 | - require 'yaml' | |
5 | - config = YAML.load_file(config_file) | |
6 | - ip = config['address'] || '127.0.0.1' | |
7 | - servers = config['servers'] || 1 | |
8 | - ports = port_range = config['port']..(config['port'] + servers - 1) | |
9 | - ports.each do |port| | |
10 | - puts "BalancerMember http://#{ip}:#{port}" | |
11 | - end | |
12 | -end | |
13 | - | |
14 | 3 | case ARGV.first |
15 | -when 'mongrel' | |
16 | - mongrel_thin(File.dirname(__FILE__) + "/../config/mongrel_cluster.yml") | |
17 | -when 'thin' | |
18 | - mongrel_thin(File.dirname(__FILE__) + "/../config/thin.yml") | |
19 | 4 | when 'virtualhosts' |
20 | 5 | require File.dirname(__FILE__) + '/../config/environment' |
21 | 6 | Environment.all.each do |environment| |
... | ... | @@ -38,6 +23,6 @@ when 'virtualhosts' |
38 | 23 | end |
39 | 24 | puts "# vim: ft=apache" |
40 | 25 | else |
41 | - puts "usage: %s mongrel|thin|virtualhosts" % $PROGRAM_NAME | |
26 | + puts "usage: %s virtualhosts" % $PROGRAM_NAME | |
42 | 27 | exit 1 |
43 | 28 | end | ... | ... |
script/development
... | ... | @@ -9,9 +9,9 @@ stop() { |
9 | 9 | ./script/delayed_job stop |
10 | 10 | ./script/feed-updater stop |
11 | 11 | whenever --clear-crontab |
12 | - if [ -f tmp/pids/thin.pid ]; then | |
13 | - kill -9 $(cat tmp/pids/thin.pid) | |
14 | - rm -f tmp/pids/thin.pid | |
12 | + if [ -f tmp/pids/unicorn.pid ]; then | |
13 | + kill -9 $(cat tmp/pids/unicorn.pid) | |
14 | + rm -f tmp/pids/unicorn.pid | |
15 | 15 | fi |
16 | 16 | exit |
17 | 17 | } |
... | ... | @@ -20,18 +20,17 @@ start() { |
20 | 20 | rake db:abort_if_pending_migrations |
21 | 21 | ./script/feed-updater start |
22 | 22 | ./script/delayed_job start |
23 | - trap stop INT TERM | |
23 | + trap stop INT TERM EXIT | |
24 | 24 | whenever --write-crontab --set 'environment=development' |
25 | 25 | if [ -z "$RAILS_RELATIVE_URL_ROOT" ]; then |
26 | - rails s $@ | |
26 | + unicorn_rails --config-file lib/noosfero/unicorn.rb $@ | |
27 | 27 | else |
28 | 28 | mkdir -p log |
29 | 29 | touch log/development.log |
30 | - thin \ | |
31 | - --prefix "$RAILS_RELATIVE_URL_ROOT" \ | |
32 | - --pid tmp/pids/thin.pid \ | |
33 | - --daemonize \ | |
34 | - start | |
30 | + unicorn_rails \ | |
31 | + --path "$RAILS_RELATIVE_URL_ROOT" \ | |
32 | + --config-file lib/noosfero/unicorn.rb \ | |
33 | + --daemonize | |
35 | 34 | tail -n 0 -f log/development.log || true |
36 | 35 | fi |
37 | 36 | } | ... | ... |
script/install-dependencies/debian-wheezy.sh
... | ... | @@ -72,8 +72,8 @@ run sudo apt-get -qy dist-upgrade |
72 | 72 | |
73 | 73 | run sudo apt-get -y install dctrl-tools |
74 | 74 | |
75 | -# *sigh* need ruby-rspec from backports | |
76 | -run sudo apt-get -y install -t wheezy-backports ruby-rspec | |
75 | +# need these from backports | |
76 | +run sudo apt-get -y install -t wheezy-backports ruby-rspec unicorn | |
77 | 77 | |
78 | 78 | # needed to run noosfero |
79 | 79 | packages=$(grep-dctrl -n -s Build-Depends,Depends,Recommends -S -X noosfero debian/control | sed -e '/^\s*#/d; s/([^)]*)//g; s/,\s*/\n/g' | grep -v 'memcached\|debconf\|dbconfig-common\|misc:Depends\|adduser\|mail-transport-agent') | ... | ... |
script/production
... | ... | @@ -25,12 +25,31 @@ clear_cache() { |
25 | 25 | fi |
26 | 26 | } |
27 | 27 | |
28 | +app_server_start() { | |
29 | + ruby -S bundle exec unicorn_rails \ | |
30 | + --config-file lib/noosfero/unicorn.rb \ | |
31 | + --env "$RAILS_ENV" \ | |
32 | + --daemonize | |
33 | +} | |
34 | + | |
35 | +app_server_stop() { | |
36 | + # see unicorn_rails(1) | |
37 | + kill -s QUIT $(cat tmp/pids/unicorn.pid) | |
38 | +} | |
39 | + | |
40 | +app_server_restart() { | |
41 | + # see unicorn_rails(1) and "Signal handling" in unicorn documentation | |
42 | + kill -s USR2 $(cat tmp/pids/unicorn.pid) | |
43 | + sleep 5 | |
44 | + kill -s QUIT $(cat tmp/pids/unicorn.pid.oldbin) | |
45 | +} | |
46 | + | |
28 | 47 | do_start() { |
29 | 48 | bundle exec rake db:migrate SCHEMA=/dev/null |
30 | 49 | clear_cache |
31 | 50 | environments_loop start |
32 | 51 | bundle exec whenever --write-crontab --set 'environment=production' |
33 | - ruby -S bundle exec thin -C config/thin.yml start | |
52 | + app_server_start | |
34 | 53 | } |
35 | 54 | |
36 | 55 | do_stop() { |
... | ... | @@ -39,8 +58,8 @@ do_stop() { |
39 | 58 | # back to stopping the daemons by manually reading their PID files, killing |
40 | 59 | # them and wiping the PID files. |
41 | 60 | |
42 | - ruby -S bundle exec thin -C config/thin.yml stop || | |
43 | - stop_via_pid_file tmp/pids/thin.*.pid | |
61 | + app_server_stop || | |
62 | + stop_via_pid_file tmp/pids/unicorn.pid | |
44 | 63 | |
45 | 64 | environments_loop stop || |
46 | 65 | stop_via_pid_file tmp/pids/delayed_job.pid tmp/pids/delayed_job.*.pid tmp/pids/feed-updater.*.pid |
... | ... | @@ -52,10 +71,11 @@ do_restart() { |
52 | 71 | bundle exec rake db:migrate SCHEMA=/dev/null |
53 | 72 | environments_loop stop || |
54 | 73 | stop_via_pid_file tmp/pids/delayed_job.pid tmp/pids/delayed_job.*.pid tmp/pids/feed-updater.*.pid |
55 | - environments_loop start | |
56 | 74 | |
57 | 75 | clear_cache |
58 | - ruby -S bundle exec thin -C config/thin.yml restart --onebyone | |
76 | + app_server_restart | |
77 | + | |
78 | + environments_loop start | |
59 | 79 | } |
60 | 80 | |
61 | 81 | stop_via_pid_file() { |
... | ... | @@ -85,7 +105,7 @@ environments_loop() { |
85 | 105 | } |
86 | 106 | |
87 | 107 | do_running() { |
88 | - pids=$(sed "s/.*/& /" tmp/pids/thin.*.pid 2>/dev/null | tr -d '\n') | |
108 | + pids=$(sed "s/.*/& /" tmp/pids/unicorn.pid 2>/dev/null | tr -d '\n') | |
89 | 109 | # passes if any of $pids exist, fails otherwise |
90 | 110 | kill -0 $pids > /dev/null 2>&1 |
91 | 111 | } |
... | ... | @@ -111,6 +131,8 @@ case "$ACTION" in |
111 | 131 | ;; |
112 | 132 | |
113 | 133 | *) |
134 | + # `running` is not listed on purpose since it's not supposed to be a public | |
135 | + # API. | |
114 | 136 | echo "usage: $0 start|stop|restart|run" |
115 | 137 | exit 1 |
116 | 138 | ;; | ... | ... |