Created
June 9, 2014 16:43
-
-
Save rlister/e60ffc6df8f8f15ffc8f to your computer and use it in GitHub Desktop.
foreman export from capistrano, then restart application using monit
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
## export upstart config using foreman | |
namespace :foreman do | |
desc "Export Procfile to upstart" | |
task :export do | |
links = { | |
'.env' => "~#{fetch(:foreman_user)}/#{fetch(:application)}/env", | |
'.foreman' => "~#{fetch(:foreman_user)}/#{fetch(:application)}/foreman", | |
} | |
on roles(:app) do | |
within(release_path) do | |
links.each do |link, src| | |
execute :if, "[ -f #{src} ];", :then, "ln -sf #{src} #{link};", :fi | |
end | |
execute :bundle, :exec, :foreman, :export, :upstart, '/etc/init' | |
end | |
end | |
end | |
end | |
after 'deploy:updated', 'foreman:export' |
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
## adds monit tasks to restart service | |
## this is preferential to using upstart directly, as it will prevent | |
## triggering alarms on deploy | |
namespace :monit do | |
desc "Start the application services using monit" | |
task :start do | |
on roles(:app) do | |
execute :sudo, 'monit start', fetch(:application) | |
end | |
end | |
desc "Stop the application services using monit" | |
task :stop do | |
on roles(:app) do | |
execute :sudo, 'monit stop', fetch(:application) | |
end | |
end | |
## do not use restart, it will error if nothing running, and if running | |
## will not reload the upstart configs, do a safe stop, then start | |
desc "Restart the application services using monit" | |
task :restart do | |
on roles(:app) do | |
execute :sudo, 'monit restart', fetch(:application) | |
end | |
end | |
end | |
after 'deploy:publishing', 'monit:restart' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment