2012-10-15 23:08:19 -04:00
|
|
|
Capistrano::Configuration.instance.load do
|
|
|
|
|
2013-04-17 16:58:44 -04:00
|
|
|
# Ensure the tmp/sockets directory is created by the deploy:setup task and
|
|
|
|
# symlinked in by the deploy:update task. This is not handled by Capistrano
|
|
|
|
# v2 but is fixed in v3.
|
|
|
|
shared_children.push('tmp/sockets')
|
|
|
|
|
2013-12-10 14:36:02 -05:00
|
|
|
_cset(:puma_default_hooks) { true }
|
2013-07-09 13:52:42 -04:00
|
|
|
_cset(:puma_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec puma" }
|
2013-03-16 02:10:06 -04:00
|
|
|
_cset(:pumactl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec pumactl" }
|
2013-07-09 13:52:42 -04:00
|
|
|
_cset(:puma_env) { fetch(:rack_env, fetch(:rails_env, 'production')) }
|
|
|
|
_cset(:puma_state) { "#{shared_path}/sockets/puma.state" }
|
2013-06-17 02:36:59 -04:00
|
|
|
_cset(:puma_socket) { "unix://#{shared_path}/sockets/puma.sock" }
|
2013-07-09 13:52:42 -04:00
|
|
|
_cset(:puma_role) { :app }
|
2012-10-15 23:08:19 -04:00
|
|
|
|
2013-12-10 14:36:02 -05:00
|
|
|
if fetch(:puma_default_hooks)
|
|
|
|
after 'deploy:stop', 'puma:stop'
|
|
|
|
after 'deploy:start', 'puma:start'
|
|
|
|
after 'deploy:restart', 'puma:restart'
|
|
|
|
end
|
|
|
|
|
2012-10-15 23:08:19 -04:00
|
|
|
namespace :puma do
|
2013-03-16 02:10:06 -04:00
|
|
|
desc 'Start puma'
|
2013-07-09 13:52:42 -04:00
|
|
|
task :start, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
|
|
|
run "cd #{current_path} && #{puma_cmd} #{start_options}", :pty => false
|
2012-10-15 23:08:19 -04:00
|
|
|
end
|
|
|
|
|
2013-03-16 02:10:06 -04:00
|
|
|
desc 'Stop puma'
|
2013-07-09 13:52:42 -04:00
|
|
|
task :stop, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
|
|
|
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} stop"
|
2012-10-15 23:08:19 -04:00
|
|
|
end
|
|
|
|
|
2013-03-16 02:10:06 -04:00
|
|
|
desc 'Restart puma'
|
2013-07-09 13:52:42 -04:00
|
|
|
task :restart, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
2013-09-26 06:09:23 -04:00
|
|
|
begin
|
|
|
|
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} restart"
|
|
|
|
rescue Capistrano::CommandError => ex
|
|
|
|
puts "Failed to restart puma: #{ex}\nAssuming not started."
|
|
|
|
start
|
|
|
|
end
|
2012-10-15 23:08:19 -04:00
|
|
|
end
|
2013-07-09 13:52:42 -04:00
|
|
|
|
|
|
|
desc 'Restart puma (phased restart)'
|
|
|
|
task :phased_restart, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
2014-04-10 04:35:00 -04:00
|
|
|
begin
|
|
|
|
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} phased-restart"
|
|
|
|
rescue Capistrano::CommandError => ex
|
|
|
|
puts "Failed to restart puma: #{ex}\nAssuming not started."
|
|
|
|
start
|
|
|
|
end
|
2013-07-09 13:52:42 -04:00
|
|
|
end
|
|
|
|
|
2012-10-15 23:08:19 -04:00
|
|
|
end
|
2013-07-09 12:32:35 -04:00
|
|
|
|
|
|
|
def start_options
|
|
|
|
if config_file
|
|
|
|
"-q -d -e #{puma_env} -C #{config_file}"
|
|
|
|
else
|
2013-07-09 13:52:42 -04:00
|
|
|
"-q -d -e #{puma_env} -b '#{puma_socket}' -S #{state_path} --control 'unix://#{shared_path}/sockets/pumactl.sock'"
|
2013-07-09 12:32:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def config_file
|
|
|
|
@_config_file ||= begin
|
|
|
|
file = fetch(:puma_config_file, nil)
|
|
|
|
file = "./config/puma/#{puma_env}.rb" if !file && File.exists?("./config/puma/#{puma_env}.rb")
|
|
|
|
file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def puma_env
|
|
|
|
fetch(:rack_env, fetch(:rails_env, 'production'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def state_path
|
2013-07-09 13:52:42 -04:00
|
|
|
(config_file ? configuration.options[:state] : nil) || puma_state
|
2013-07-09 12:32:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def configuration
|
|
|
|
require 'puma/configuration'
|
|
|
|
|
|
|
|
config = Puma::Configuration.new(:config_file => config_file)
|
|
|
|
config.load
|
|
|
|
config
|
|
|
|
end
|
2012-10-19 22:16:18 -04:00
|
|
|
end
|