Skip to content

Instantly share code, notes, and snippets.

@emilioeduardob
Last active September 29, 2016 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilioeduardob/4b0842980c38374d9a1a55addc927c43 to your computer and use it in GitHub Desktop.
Save emilioeduardob/4b0842980c38374d9a1a55addc927c43 to your computer and use it in GitHub Desktop.
Capistrano recipe for Mailman
set :mailman_cmd, -> { "#{fetch(:bundle_cmd, 'bundle')} exec mailman" }
set :mailman_config, -> { "#{current_path}/config/mailman.rb" }
set :mailman_role, -> { :app }
set :mailman_pid, -> { "#{current_path}/tmp/pids/mailman.pid" }
namespace :mailman do
desc 'Stop mailman'
task :stop do
on roles(:app) do
execute "if [ -d #{current_path} ] && [ -f #{fetch(:mailman_pid)} ] && kill -0 `cat #{fetch(:mailman_pid)}` > /dev/null 2>&1; then cd #{current_path} && rm #{fetch(:mailman_pid)} ; else echo 'Mailman is not running'; fi"
end
end
desc 'Start mailman'
task :start do
on roles(:app) do
execute "cd #{current_path} ; nohup #{fetch(:mailman_cmd)} -c #{fetch(:mailman_config)} -p #{fetch(:mailman_pid)} -e #{fetch(:rails_env, 'production')} >> #{current_path}/log/mailman.log 2>&1 &", pty: false
end
end
desc 'Restart mailman'
task :restart do
invoke 'mailman:stop'
invoke 'mailman:start'
end
end
before 'puma:stop', 'mailman:stop'
after 'puma:start', 'mailman:start'
before 'puma:restart', 'mailman:restart'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment