Created
June 16, 2014 13:37
-
-
Save teitei-tk/54ce08c2b1be8989a79f to your computer and use it in GitHub Desktop.
Rakefileにunicorn起動・停止のコマンドを追加する ref: http://qiita.com/teitei_tk/items/2f997d1b916905da6c80
This file contains 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
require File.expand_path('../config/application', __FILE__) | |
Rails.application.load_tasks | |
namespace :unicorn do | |
## | |
# Tasks | |
## | |
desc "Start unicorn" | |
task(:start) { | |
config = rails_root + "config/unicorn.rb" | |
sh "bundle exec unicorn_rails -c #{config} -E development -D" | |
} | |
desc "Stop unicorn" | |
task(:stop) { unicorn_signal :QUIT } | |
desc "Restart unicorn with USR2" | |
task(:restart) { unicorn_signal :USR2 } | |
desc "Increment number of worker processes" | |
task(:increment) { unicorn_signal :TTIN } | |
desc "Decrement number of worker processes" | |
task(:decrement) { unicorn_signal :TTOU } | |
desc "Unicorn pstree (depends on pstree command)" | |
task(:pstree) do | |
sh "pstree '#{unicorn_pid}'" | |
end | |
## | |
# Helpers | |
## | |
def unicorn_signal signal | |
Process.kill signal, unicorn_pid | |
end | |
def unicorn_pid | |
begin | |
File.read("/tmp/unicorn.pid").to_i | |
rescue Errno::ENOENT | |
raise "Unicorn doesn't seem to be running" | |
end | |
end | |
def rails_root | |
require "pathname" | |
Pathname.new(__FILE__) + "../" | |
end | |
end |
This file contains 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
require File.expand_path('../config/application', __FILE__) | |
Rails.application.load_tasks | |
namespace :unicorn do | |
## | |
# Tasks | |
## | |
desc "Start unicorn" | |
task(:start) { | |
config = rails_root + "config/unicorn.rb" | |
sh "bundle exec unicorn_rails -c #{config} -E development -D" | |
} | |
desc "Stop unicorn" | |
task(:stop) { unicorn_signal :QUIT } | |
desc "Restart unicorn with USR2" | |
task(:restart) { unicorn_signal :USR2 } | |
desc "Increment number of worker processes" | |
task(:increment) { unicorn_signal :TTIN } | |
desc "Decrement number of worker processes" | |
task(:decrement) { unicorn_signal :TTOU } | |
desc "Unicorn pstree (depends on pstree command)" | |
task(:pstree) do | |
sh "pstree '#{unicorn_pid}'" | |
end | |
## | |
# Helpers | |
## | |
def unicorn_signal signal | |
Process.kill signal, unicorn_pid | |
end | |
def unicorn_pid | |
begin | |
File.read("/tmp/unicorn.pid").to_i | |
rescue Errno::ENOENT | |
raise "Unicorn doesn't seem to be running" | |
end | |
end | |
def rails_root | |
require "pathname" | |
Pathname.new(__FILE__) + "../" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment