Skip to content

Instantly share code, notes, and snippets.

@ricardodovalle
Created July 9, 2014 02:22
Show Gist options
  • Save ricardodovalle/42937ea61a8359b35b42 to your computer and use it in GitHub Desktop.
Save ricardodovalle/42937ea61a8359b35b42 to your computer and use it in GitHub Desktop.
Only a foreman sudo approch (not working)
namespace :foreman do
desc <<-DESC
Export the Procfile to upstart.
You can override any of these defaults by setting the variables shown below.
set :foreman_cmd, "foreman"
set :foreman_format, "upstart"
set :foreman_location, "/etc/init"
set :foreman_port, 5000
set :foreman_root, -> { release_path }
set :foreman_procfile, -> { release_path.join('Procfile') }
set :foreman_app, -> { fetch(:application) }
set :foreman_log, -> { shared_path.join('log') }
set :foreman_pids, false
set :foreman_concurrency, false
set :foreman_sudo, false
set :foreman_roles, :all
set :foreman_servers, -> { release_roles(fetch(:foreman_roles)) }
DESC
task :export do
on fetch(:foreman_servers) do |host|
within release_path do
foreman_cmd = fetch(:foreman_cmd)
foreman_concurrency = fetch(:foreman_concurrency)
foreman_format = fetch(:foreman_format)
foreman_location = deploy_path.join('upstart')
foreman_pids = fetch(:foreman_pids)
foreman_user = fetch(:foreman_user, host.user)
cmd = [foreman_cmd, 'export', foreman_format, foreman_location]
cmd << %Q(-f #{fetch(:foreman_procfile)})
cmd << %Q(-p #{fetch(:foreman_port)})
cmd << %Q(-d #{fetch(:foreman_root)})
cmd << %Q(-a #{fetch(:foreman_app)})
cmd << %Q(-u #{foreman_user})
cmd << %Q(-l #{fetch(:foreman_log)})
cmd << %Q(-r #{foreman_pids}) if foreman_pids
cmd << %Q(-c #{foreman_concurrency}) if foreman_concurrency
execute :bundle, :exec, *cmd
end
end
end
task :clean do
# target = deploy_path.join('upstart')
# puts fetch(:deploy_path)
# execute :rm, '-rf', target
# execute :mkdir, '-pv', target
on release_roles :all do |host|
within deploy_path do
execute :rm, '-rf', 'upstart'
execute :mkdir, '-pv', 'upstart'
end
end
end
desc 'Prefixes the foreman command with sudo when :foreman_sudo => true'
task :configure_sudo do
if fetch(:foreman_sudo)
foreman_cmd = fetch(:foreman_cmd).to_s
SSHKit.config.command_map.prefix[foreman_cmd].push('sudo')
end
end
end
Capistrano::DSL.stages.each do |stage|
after stage, 'foreman:clean'
after stage, 'foreman:configure_sudo'
end
namespace :load do
task :defaults do
set :foreman_cmd, 'foreman'
set :foreman_format, 'upstart'
set :foreman_location, '/etc/init'
set :foreman_port, 5000
set :foreman_root, -> { release_path }
set :foreman_procfile, -> { release_path.join('Procfile') }
set :foreman_app, -> { fetch(:application) }
set :foreman_log, -> { shared_path.join('log') }
set :foreman_pids, false
set :foreman_concurrency, false
set :foreman_sudo, false
set :foreman_roles, :all
set :foreman_servers, -> { release_roles(fetch(:foreman_roles)) }
end
end
namespace :deploy do
after :updated, 'foreman:export'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment