From 7f62c5bfc4501819593e1130d8eecaae5f932297 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Wed, 9 Sep 2015 21:14:30 -0300 Subject: [PATCH] debian: switch to unicorn --- debian/apache2/conf.d/noosfero-cluster.conf | 8 -------- debian/apache2/virtualhost.conf | 6 +++++- debian/control | 2 +- debian/noosfero-apache.install | 1 - debian/noosfero.install | 2 +- debian/noosfero.links | 2 +- debian/noosfero.postinst | 24 ++++++++++++------------ debian/thin.yml | 13 ------------- debian/unicorn.rb | 3 +++ debian/update-noosfero-apache | 15 ++------------- script/apacheconf | 17 +---------------- script/install-dependencies/debian-wheezy.sh | 4 ++-- util/debian-install/test | 2 +- 13 files changed, 29 insertions(+), 70 deletions(-) delete mode 100644 debian/apache2/conf.d/noosfero-cluster.conf delete mode 100644 debian/thin.yml create mode 100644 debian/unicorn.rb diff --git a/debian/apache2/conf.d/noosfero-cluster.conf b/debian/apache2/conf.d/noosfero-cluster.conf deleted file mode 100644 index bc0ecf3..0000000 --- a/debian/apache2/conf.d/noosfero-cluster.conf +++ /dev/null @@ -1,8 +0,0 @@ - - Include /etc/noosfero/apache/cluster.conf - Order Allow,Deny - Allow from All - - -# vim: ft=apache - diff --git a/debian/apache2/virtualhost.conf b/debian/apache2/virtualhost.conf index ac7b299..c4fe4de 100644 --- a/debian/apache2/virtualhost.conf +++ b/debian/apache2/virtualhost.conf @@ -15,7 +15,11 @@ RewriteRule ^/$ /index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f -RewriteRule ^.*$ balancer://noosfero%{REQUEST_URI} [P,QSA,L] +RewriteRule ^.*$ http://127.0.0.1:50000%{REQUEST_URI} [P,QSA,L] + + Order Allow,Deny + Allow from All + ErrorDocument 503 /503.html diff --git a/debian/control b/debian/control index dd098bf..ca6714b 100644 --- a/debian/control +++ b/debian/control @@ -65,7 +65,7 @@ Depends: adduser, ruby-whenever, ruby-will-paginate (>= 2.3.12-1~), tango-icon-theme, - thin, + unicorn (>= 4.8), ${misc:Depends} Recommends: postgresql, postgresql-client Description: free web-based platform for social networks diff --git a/debian/noosfero-apache.install b/debian/noosfero-apache.install index 800d6b1..645ecb0 100644 --- a/debian/noosfero-apache.install +++ b/debian/noosfero-apache.install @@ -1,3 +1,2 @@ -debian/apache2/conf.d/noosfero-cluster.conf etc/apache2/conf.d debian/apache2/virtualhost.conf etc/noosfero/apache debian/update-noosfero-apache usr/sbin diff --git a/debian/noosfero.install b/debian/noosfero.install index 0eef3ee..ff6dfdc 100644 --- a/debian/noosfero.install +++ b/debian/noosfero.install @@ -19,7 +19,7 @@ debian/noosfero-check-dbconfig usr/sbin debian/noosfero-console usr/sbin debian/noosfero-runner usr/sbin debian/noosfero.yml etc/noosfero -debian/thin.yml etc/noosfero +debian/unicorn.rb etc/noosfero doc usr/share/noosfero doc/noosfero usr/share/noosfero/doc etc/init.d/noosfero etc/init.d diff --git a/debian/noosfero.links b/debian/noosfero.links index 6e24387..eea35ee 100644 --- a/debian/noosfero.links +++ b/debian/noosfero.links @@ -1,7 +1,7 @@ var/tmp/noosfero usr/share/noosfero/tmp var/log/noosfero usr/share/noosfero/log etc/noosfero/database.yml usr/share/noosfero/config/database.yml -etc/noosfero/thin.yml usr/share/noosfero/config/thin.yml +etc/noosfero/unicorn.rb usr/share/noosfero/config/unicorn.rb etc/noosfero/plugins usr/share/noosfero/config/plugins etc/noosfero/noosfero.yml usr/share/noosfero/config/noosfero.yml etc/noosfero/local.rb usr/share/noosfero/config/local.rb diff --git a/debian/noosfero.postinst b/debian/noosfero.postinst index 3dfe077..9d3ac26 100644 --- a/debian/noosfero.postinst +++ b/debian/noosfero.postinst @@ -10,23 +10,23 @@ makedir() { } -# migrate mongrel configuration to thin -mongrel_config=/etc/noosfero/mongrel_cluster.yml +# migrate thin configuration to unicorn +unicorn_config=/etc/noosfero/unicorn.rb thin_config=/etc/noosfero/thin.yml -mongrel_orig_sha1=602c642c03f79349969c08330112a6f29d4c32aa -if [ -r $mongrel_config ]; then - mongrel_sha1=$(sha1sum $mongrel_config | awk '{print $1}') - if [ "$mongrel_sha1" != "$mongrel_orig_sha1" ]; then - port=$(awk '{ if ($1 == "port:") { print($2) } }' $mongrel_config) - servers=$(awk '{ if ($1 == "servers:") { print($2) } }' $mongrel_config) +thin_orig_sha1=47cee6728a7896a13f4d66544086ab88b02e89a7 +if [ -r $thin_config ]; then + thin_sha1=$(sha1sum $thin_config | awk '{print $1}') + if [ "$thin_sha1" != "$thin_orig_sha1" ]; then + port=$(awk '{ if ($1 == "port:") { print($2) } }' $thin_config) + servers=$(awk '{ if ($1 == "servers:") { print($2) } }' $thin_config) if test -n "$port" && test "$port" -ne 50000 || test -n "$servers" && test "$servers" -ne 1 ; then - # mongrel configuration was changed; update thin configuration + # thin configuration was changed; update unicorn configuration # accordingly - sed -i -e "s/port: .*/port: $port/" $thin_config - sed -i -e "s/servers: .*/servers: $servers/" $thin_config + sed -i -e "s/listen.*/listen '127.0.0.1:$port'/" $unicorn_config + sed -i -e "s/worker_processes.*/worker_processes $servers/" $unicorn_config fi fi - mv $mongrel_config $mongrel_config.bak + mv $thin_config $thin_config.bak fi # create user noosfero in a portable way, while creating the log directory. diff --git a/debian/thin.yml b/debian/thin.yml deleted file mode 100644 index 8a3ab4e..0000000 --- a/debian/thin.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -pid: tmp/pids/thin.pid -address: 127.0.0.1 -user: noosfero -timeout: 0 -port: 50000 -log: log/thin.log -max_conns: 1024 -servers: 1 -max_persistent_conns: 512 -environment: production -daemonize: true -chdir: /usr/share/noosfero diff --git a/debian/unicorn.rb b/debian/unicorn.rb new file mode 100644 index 0000000..c005a9a --- /dev/null +++ b/debian/unicorn.rb @@ -0,0 +1,3 @@ +listen "127.0.0.1:50000" + +worker_processes `nproc`.to_i diff --git a/debian/update-noosfero-apache b/debian/update-noosfero-apache index 359cd26..0be9ceb 100755 --- a/debian/update-noosfero-apache +++ b/debian/update-noosfero-apache @@ -2,20 +2,9 @@ set -e -# automatically update configuration, but if package noosfero is also installed +# automatically update configuration, but only if package noosfero is also +# installed if test -x /usr/share/noosfero/script/apacheconf; then - datadir="/etc/noosfero/apache" - mongrel_file="$datadir/mongrel.conf" - cluster_file="$datadir/cluster.conf" - if test -e "$cluster_file"; then - echo "Overwriting $cluster_file ..." - fi - /usr/share/noosfero/script/apacheconf thin > "$cluster_file" - if test -e "$mongrel_file"; then - echo "Moving existing $mongrel_file away ..." - mv "$mongrel_file" "$mongrel_file".bak - (cd $datadir && ln -sf cluster.conf mongrel.conf) - fi apache_site='/etc/apache2/sites-available/noosfero' if ! test -e "$apache_site"; then diff --git a/script/apacheconf b/script/apacheconf index 589c2b8..71251d1 100755 --- a/script/apacheconf +++ b/script/apacheconf @@ -1,21 +1,6 @@ #!/usr/bin/env ruby -def mongrel_thin(config_file) - require 'yaml' - config = YAML.load_file(config_file) - ip = config['address'] || '127.0.0.1' - servers = config['servers'] || 1 - ports = port_range = config['port']..(config['port'] + servers - 1) - ports.each do |port| - puts "BalancerMember http://#{ip}:#{port}" - end -end - case ARGV.first -when 'mongrel' - mongrel_thin(File.dirname(__FILE__) + "/../config/mongrel_cluster.yml") -when 'thin' - mongrel_thin(File.dirname(__FILE__) + "/../config/thin.yml") when 'virtualhosts' require File.dirname(__FILE__) + '/../config/environment' Environment.all.each do |environment| @@ -38,6 +23,6 @@ when 'virtualhosts' end puts "# vim: ft=apache" else - puts "usage: %s mongrel|thin|virtualhosts" % $PROGRAM_NAME + puts "usage: %s virtualhosts" % $PROGRAM_NAME exit 1 end diff --git a/script/install-dependencies/debian-wheezy.sh b/script/install-dependencies/debian-wheezy.sh index 22c932c..1d8762d 100644 --- a/script/install-dependencies/debian-wheezy.sh +++ b/script/install-dependencies/debian-wheezy.sh @@ -72,8 +72,8 @@ run sudo apt-get -qy dist-upgrade run sudo apt-get -y install dctrl-tools -# *sigh* need ruby-rspec from backports -run sudo apt-get -y install -t wheezy-backports ruby-rspec +# need these from backports +run sudo apt-get -y install -t wheezy-backports ruby-rspec unicorn # needed to run noosfero 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') diff --git a/util/debian-install/test b/util/debian-install/test index ffbea30..888b64a 100755 --- a/util/debian-install/test +++ b/util/debian-install/test @@ -1,7 +1,7 @@ #!/bin/sh test_web_backend_running() { - assertTrue 'Noosfero running' 'pgrep -u noosfero -f thin' + assertTrue 'Noosfero running' 'pgrep -u noosfero -f unicorn' } test_delayed_job_running() { -- libgit2 0.21.2