-
-
Save causztic/5251078 to your computer and use it in GitHub Desktop.
Capistrano running clockwork as daemon with upstart
This file contains 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
after "deploy:stop", "clockwork:stop" | |
after "deploy:start", "clockwork:start" | |
after "deploy:restart", "clockwork:restart" | |
set :clockwork_roles, :blabla | |
set :cw_log_file, "#{current_path}/log/clockwork.log" | |
set :cw_pid_file, "#{current_path}/tmp/pids/clockwork.pid" | |
set :rails_env, ENV['rails_env'] || '' | |
namespace :clockwork do | |
desc "Stop clockwork" | |
task :stop, :roles => :app, :on_no_matching_servers => :continue do | |
#2>/dev/null skips errors if the file is found but process is not running for some reason | |
run "if [ -d #{current_path} ] && [ -f #{cw_pid_file} ]; then cd #{current_path} && kill -int $(cat #{cw_pid_file}) 2>/dev/null; else echo 'clockwork was not running' ; fi" | |
end | |
desc "Start clockwork" | |
task :start, :roles => :app, :on_no_matching_servers => :continue do | |
run "cd #{current_path}; nohup bundle exec clockwork config/clockwork.rb -e #{rails_env} >> #{current_path}/log/clockwork.log 2>&1 &", :pty => false | |
# get process id | |
run "ps -eo pid,command | grep clockwork | grep -v grep | awk '{print $1}' > #{cw_pid_file}" | |
end | |
desc "Restart clockwork" | |
task :restart, :roles => #{clockwork_roles}, :on_no_matching_servers => :continue do | |
stop | |
start | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated my hastily coded tasks to catch the pid correctly and some error scenarios.