Permalink
Browse files

migrate from unicorn to puma

  • Loading branch information...
1 parent b717d7d commit e5aa1f6b2c406624d83702befd4a143675a65680 @ck3g committed Apr 6, 2013
Showing with 46 additions and 57 deletions.
  1. +3 −2 Gemfile
  2. +3 −10 Gemfile.lock
  3. +27 −2 config/deploy.rb
  4. +13 −0 config/puma.rb
  5. +0 −43 config/unicorn/production.rb
View
@@ -49,7 +49,6 @@ group :development do
gem "capistrano", "~> 2.14.2", :require => false
gem 'capistrano-recipes', :require => false
gem 'capistrano_colors', :require => false
- gem 'capistrano-unicorn', '~> 0.1.6', require: false
gem "rails_best_practices"
gem "thin"
gem "zeus"
@@ -70,4 +69,6 @@ group :test do
gem "email_spec", "~> 1.2.1"
end
-gem "unicorn", "~> 4.6.0", group: [:development, :production]
+group :production do
+ gem "puma"
+end
View
@@ -59,8 +59,6 @@ GEM
capistrano-recipes (0.8.0)
capistrano (>= 2.5.9)
capistrano-ext (>= 1.2.1)
- capistrano-unicorn (0.1.7)
- capistrano
capistrano_colors (0.5.5)
capybara (1.1.4)
mime-types (>= 1.16)
@@ -135,7 +133,6 @@ GEM
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
- kgio (2.8.0)
launchy (2.1.2)
addressable (~> 2.3)
libv8 (3.11.8.13)
@@ -177,6 +174,8 @@ GEM
slop (~> 3.3.1)
pry-rails (0.2.2)
pry (>= 0.9.10)
+ puma (1.6.3)
+ rack (~> 1.2)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
@@ -207,7 +206,6 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
- raindrops (0.10.0)
rake (10.0.3)
rdoc (3.12.2)
json (~> 1.4)
@@ -293,10 +291,6 @@ GEM
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
- unicorn (4.6.2)
- kgio (~> 2.6)
- rack
- raindrops (~> 0.7)
warden (1.2.1)
rack (>= 1.0)
websocket (1.0.6)
@@ -318,7 +312,6 @@ DEPENDENCIES
cancan (~> 1.6.8)
capistrano (~> 2.14.2)
capistrano-recipes
- capistrano-unicorn (~> 0.1.6)
capistrano_colors
capybara (~> 1.1.2)
carrierwave (~> 0.8.0)
@@ -340,6 +333,7 @@ DEPENDENCIES
mini_magick (~> 3.5.0)
pg
pry-rails
+ puma
rails (~> 3.2.13)
rails_best_practices
rspec-rails (~> 2.11.0)
@@ -353,5 +347,4 @@ DEPENDENCIES
tiny_tds (~> 0.5.1)
twitter_cldr (~> 2.2.0)
uglifier (>= 1.0.3)
- unicorn (~> 4.6.0)
zeus
View
@@ -10,7 +10,7 @@
set :application, "sc2_news"
set :deploy_to, "/home/#{user}/apps/#{application}/"
set :branch, "master"
-set :unicorn_env, "production"
+set :puma_env, "production"
set :rails_env, "production"
#default_run_options[:shell] = '/bin/bash'
@@ -74,7 +74,32 @@
end
end
+after 'deploy:stop', 'puma:stop'
+after 'deploy:start', 'puma:start'
+after 'deploy:restart', 'puma:restart'
+
+_cset(:puma_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec puma" }
+_cset(:pumactl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec pumactl" }
+_cset(:puma_state) { "#{shared_path}/sockets/puma.state" }
+_cset(:puma_role) { :app }
+
+namespace :puma do
+ desc 'Start puma'
+ task :start, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
+ run "cd #{current_path} && #{fetch(:puma_cmd)} -t 4:4 -q -e #{puma_env} -b 'unix://#{shared_path}/sockets/puma.sock' -S #{fetch(:puma_state)} --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{puma_env}.log 2>&1 &", :pty => false
+ end
+
+ desc 'Stop puma'
+ task :stop, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
+ run "cd #{current_path} && #{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} stop"
+ end
+
+ desc 'Restart puma'
+ task :restart, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
+ run "cd #{current_path} && #{fetch(:pumactl_cmd)} -S #{fetch(:puma_state)} restart"
+ end
+end
+
require 'capistrano_colors'
require 'bundler/capistrano'
-require "capistrano-unicorn"
View
@@ -0,0 +1,13 @@
+rails_env = ENV["RAILS_ENV"] || "development"
+
+threads 4,4
+
+deploy_to = "/home/kalastiuz/apps/sc2_news"
+app_path = "#{deploy_to}/current"
+shared_path = "#{deploy_to}/shared"
+
+bind "unix://#{shared_path}/sockets/puma.sock"
+pidfile "#{app_path}/tmp/puma/pid"
+state_path "#{app_path}/tmp/puma/state"
+
+activate_control_app
@@ -1,43 +0,0 @@
-# Set your full path to application.
-deploy_to = "/home/kalastiuz/apps/sc2_news"
-app_path = "#{deploy_to}/current"
-shared_path = "#{deploy_to}/shared"
-
-# Set unicorn options
-worker_processes 8
-preload_app true
-timeout 120
-listen "#{shared_path}/sockets/unicorn.sock", :backlog => 2048
-
-# Spawn unicorn master worker for user apps (group: apps)
-user 'kalastiuz', 'kalastiuz'
-
-# Fill path to your app
-working_directory app_path
-
-# Should be 'production' by default, otherwise use other env
-rails_env = ENV['RAILS_ENV'] || 'production'
-
-# Log everything to one file
-stderr_path "#{shared_path}/log/unicorn.stderr.log"
-stdout_path "#{shared_path}/log/unicorn.stdout.log"
-
-# Set master PID location
-pid "#{app_path}/tmp/pids/unicorn.pid"
-
-before_fork do |server, worker|
- ActiveRecord::Base.connection.disconnect!
-
- old_pid = "#{server.config[: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
- # someone else did our job for us
- end
- end
-end
-
-after_fork do |server, worker|
- ActiveRecord::Base.establish_connection
-end

0 comments on commit e5aa1f6

Please sign in to comment.