Skip to content

Instantly share code, notes, and snippets.

@unorthodoxgeek
unorthodoxgeek / deploy.rb
Created September 14, 2012 20:42
Capistrano deploy.rb
namespace :deploy do
task :start, :roles => :web, :except => { :no_release => true } do
run "cd #{current_path} && rvmsudo #{unicorn_binary} -c #{unicorn_config} -E #{env} -D"
end
task :stop, :roles => :web, :except => { :no_release => true } do
run "ps aux | grep unicorn | grep master | grep -v grep | awk {'print $2'} | xargs -r sudo kill -s QUIT"
#run "rvmsudo kill -s QUIT `cat #{unicorn_pid}`"
end
@unorthodoxgeek
unorthodoxgeek / nginx
Created September 14, 2012 20:37
nginx configuration for unicorn
upstream app_server {
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
root /srv/deploy/current/public;
try_files $uri/index.html $uri.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
@unorthodoxgeek
unorthodoxgeek / unicorn.rb
Created September 14, 2012 20:28
unicorn server configuration
# run unicorn with unicorn -c Rails.root/current/config/unicorn.rb -E production -D
rails_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
# 12 workers and 1 master
worker_processes (rails_env == 'production' ? 12 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@unorthodoxgeek
unorthodoxgeek / social_graph.rb
Created October 22, 2011 10:15
social graph ruby + redis
include Redis::Objects
counter :visits, :start => 0
counter :likes, :start => 0
set :following
set :followers
def follow( user )
self.following << user.id
user.followers << id
end