Last active
January 1, 2016 03:09
-
-
Save alepore/8083925 to your computer and use it in GitHub Desktop.
Capistrano 3 recipe for Puma.
Put in lib/capistrano/tasks/puma.cap .
Expects the use of bundle and a complete Puma config file in config/puma/<environment>.rb .
RVM compatible (gem 'capistrano-rvm').
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
commands = %w(start stop restart phased-restart status stats halt) | |
namespace :deploy do | |
desc 'Puma web server Start' | |
task :start do | |
on roles(:app), in: :sequence, wait: 5 do | |
within current_path do | |
execute :bundle, "exec puma -C #{config_file}" | |
end | |
end | |
end | |
(commands - ['start']).each do |command| | |
desc "Puma web server #{command.capitalize}" | |
task command.to_sym do | |
on roles(:app), in: :sequence, wait: 5 do | |
within current_path do | |
if command =~ /restart$/ && !test("[ -f #{pid_path} ]") | |
Rake::Task['deploy:start'].invoke | |
else | |
execute :bundle, "exec pumactl -F #{config_file} #{command}" | |
end | |
end | |
end | |
end | |
end | |
# RVM integration | |
if Gem::Specification::find_all_by_name('capistrano-rvm').any? | |
commands.each do |command| | |
before command.to_sym, 'rvm:hook' | |
end | |
end | |
end | |
def config_file | |
"./config/puma/#{fetch(:stage)}.rb" | |
end | |
def state_path | |
configuration.options[:state] | |
end | |
def pid_path | |
configuration.options[:pidfile] | |
end | |
def configuration | |
require 'puma/configuration' | |
config = Puma::Configuration.new(config_file: config_file) | |
config.load | |
config | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment