Created
January 30, 2011 05:17
-
-
Save BinaryMuse/802568 to your computer and use it in GitHub Desktop.
DND - blog post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install RVM and dependencies | |
sudo aptitude install curl git-core | |
sudo bash < <( curl -L http://bit.ly/rvm-install-system-wide ) | |
sudo aptitude install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev | |
sudo adduser `whoami` rvm | |
echo 'source /usr/local/lib/rvm' >> ~/.bashrc | |
# Set up users and groups | |
sudo useradd --home /var/www --create-home --groups rvm unicorn && sudo chmod g+w /var/www | |
sudo adduser `whoami` unicorn | |
# | |
# >> Log out and back in to SSH, open a new shell, etc. -- something to reload your environment | |
# | |
# Install Ruby 1.9.2-p136 and make it default | |
rvm install ruby-1.9.2-p136 | |
# Make a sandwich while you wait (or have someone make you one: http://xkcd.com/149/) | |
rvm use ruby-1.9.2-p136 --default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install Nginx | |
sudo bash -c 'echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/nginx-stable-$(lsb_release -cs).list' | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C && sudo aptitude update | |
sudo aptitude install nginx | |
sudo bash -c 'curl -L https://gist.github.com/raw/802568/3a62636146eb2615cf42081b2574e8602d199658/nginx.conf > /etc/nginx/nginx.conf' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo rm /etc/init.d/nginx | |
for file in $(ls /etc/rc*/*nginx); do sudo rm $file; done | |
sudo bash -c 'curl -L https://gist.github.com/raw/802568/e210f8754abdf137027daeb4c41db8cc301b36ad/nginx.conf > /etc/init/nginx.conf' | |
sudo start nginx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install Unicorn in the global gemset, and create a wrapper (yo yo yo in the hooouuuuuse!?) | |
rvm use ruby-1.9.2-p136@global | |
gem install unicorn --no-ri --no-rdoc | |
rvm wrapper ruby-1.9.2-p136 r192 unicorn | |
# Create and switch to a new gemset | |
rvm gemset create rails_app && rvm gemset use rails_app | |
gem install rails --no-ri --no-rdoc | |
# Create a sample Rails application | |
cd /var/www | |
rails new test_app | |
echo 'rvm use ruby-1.9.2-p136@rails_app --create' > test_app/.rvmrc | |
cd test_app | |
# | |
# >> Accept the .rvmrc warning | |
# | |
echo "gem 'unicorn'" >> Gemfile && bundle install | |
curl -L https://gist.github.com/raw/802568/998ac7c702e43d600f94fc3ee63ea05179315a0d/unicorn.rb > config/unicorn.rb | |
sudo bash -c 'curl -L https://gist.github.com/raw/802568/ee3f5f320c34ec2e1d1b55521776d7dccd9140d4/test_app.conf > /etc/init/test_app.conf' | |
sudo start test_app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
user www-data www-data; | |
pid /tmp/nginx.pid; | |
error_log /tmp/nginx.error.log; | |
events { | |
worker_connections 1024; | |
accept_mutex off; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
access_log /tmp/nginx.access.log combined; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay off; | |
gzip on; | |
gzip_http_version 1.0; | |
gzip_proxied any; | |
gzip_min_length 500; | |
gzip_disable "MSIE [1-6]\."; | |
gzip_types text/plain text/html text/xml text/css | |
text/comma-separated-values | |
text/javascript application/x-javascript | |
application/atom+xml; | |
upstream unicorn_test { | |
server unix:/var/www/test_app/tmp/sockets/unicorn.sock fail_timeout=0; | |
} | |
server { | |
listen 80; | |
client_max_body_size 4G; | |
server_name _; | |
keepalive_timeout 5; | |
root /var/www/test_app/public; | |
location / { | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
if (!-f $request_filename) { | |
proxy_pass http://unicorn_test; | |
break; | |
} | |
} | |
error_page 500 502 503 504 /500.html; | |
location = /500.html { | |
root /var/www/test_app/public; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "nginx http daemon" | |
start on runlevel [2] | |
stop on runlevel [016] | |
console owner | |
exec /usr/sbin/nginx -c /etc/nginx/nginx.conf -g "daemon off;" | |
respawn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "Test rails application" | |
start on runlevel [2] | |
stop on runlevel [016] | |
console owner | |
exec /usr/local/rvm/bin/r192_unicorn -c /var/www/test_app/config/unicorn.rb | |
respawn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__))) | |
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') | |
begin | |
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) | |
rvm_lib_path = File.join(rvm_path, 'lib') | |
$LOAD_PATH.unshift rvm_lib_path | |
require 'rvm' | |
RVM.use_from_path! APP_ROOT | |
rescue LoadError | |
raise "RVM ruby lib is currently unavailable." | |
end | |
end | |
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__)) | |
require 'bundler/setup' | |
worker_processes 4 | |
working_directory APP_ROOT | |
preload_app true | |
timeout 30 | |
listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64 | |
pid APP_ROOT + "/tmp/pids/unicorn.pid" | |
stderr_path APP_ROOT + "/log/unicorn.stderr.log" | |
stdout_path APP_ROOT + "/log/unicorn.stdout.log" | |
before_fork do |server, worker| | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! | |
old_pid = RAILS_ROOT + '/tmp/pids/unicorn.pid.oldbin' | |
if File.exists?(old_pid) && server.pid != old_pid | |
begin | |
Process.kill("QUIT", File.read(old_pid).to_i) | |
rescue Errno::ENOENT, Errno::ESRCH | |
puts "Old master alerady dead" | |
end | |
end | |
end | |
after_fork do |server, worker| | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment