forked from mdespuits/capistrano-recipes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
clockwork.rb
31 lines (23 loc) · 995 Bytes
/
clockwork.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
set :clockwork_roles, :app
set :cw_log_file, "#{current_path}/log/clockwork.log"
set :cw_pid_file, "#{current_path}/tmp/pids/clockwork.pid"
set_default :clockwork_worker, "app/workers/clock_worker.rb"
namespace :clockwork do
desc "Stop clockwork"
task :stop, :roles => :app, :on_no_matching_servers => :continue do
run "[ -s #{cw_pid_file} ] && cat #{cw_pid_file} | xargs kill -int || echo 'clockwork not running' >&2"
end
desc "Start clockwork"
task :start, :roles => :app, :on_no_matching_servers => :continue do
run "cd #{current_path}; RAILS_ENV=production nohup bundle exec clockwork #{clockwork_worker} -e #{rails_env} >> #{cw_log_file} 2>&1 &", :pty => false
run "ps -C ruby -o pid,cmd | awk '$0 ~ /bin\\/clockwork/ {print $1 }' > #{cw_pid_file} "
end
desc "Restart clockwork"
task :restart do
stop
start
end
end
after "deploy:stop", "clockwork:stop"
after "deploy:start", "clockwork:start"
after "deploy:restart", "clockwork:restart"