Skip to content

Instantly share code, notes, and snippets.

@causztic
Forked from rogercampos/clockwork.rb
Last active December 18, 2019 02:00
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save causztic/5251078 to your computer and use it in GitHub Desktop.
Save causztic/5251078 to your computer and use it in GitHub Desktop.
Capistrano running clockwork as daemon with upstart
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
@causztic
Copy link
Author

causztic commented Apr 1, 2013

Updated my hastily coded tasks to catch the pid correctly and some error scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment