Skip to content

Instantly share code, notes, and snippets.

@NicosKaralis
Forked from causztic/clockwork.rb
Created September 5, 2013 12:10
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 NicosKaralis/6449292 to your computer and use it in GitHub Desktop.
Save NicosKaralis/6449292 to your computer and use it in GitHub Desktop.
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