Created
September 2, 2013 14:23
-
-
Save pzskc383/6413400 to your computer and use it in GitHub Desktop.
capistrano thingy to restart workers in tmux
This file contains hidden or 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
set :tmux_session, "mailer" | |
desc 'Restart workers' | |
task :workers do | |
tmux_window = 'workers' | |
num_workers = 4 | |
worker_cmd = "'php #{current_release}/bin/worker.php'" | |
exists = true | |
run "tmux start" | |
begin | |
ret = run "tmux has-session -t #{tmux_session} 2>&-" | |
rescue | |
exists = false | |
end | |
if exists | |
run "tmux kill-session -t #{tmux_session}" | |
panes = capture "tmux lsp -t #{tmux_session}:#{tmux_window}" | |
panes = panes.split(/\n/) | |
num_workers = [num_workers, panes.count].max | |
num_workers.times do |i| | |
run "tmux respawn-pane -k -t #{tmux_session}:#{tmux_window}.#{i} #{worker_cmd}" | |
end | |
else | |
run "tmux new-session -d -s #{tmux_session} -n #{tmux_window} #{worker_cmd}" | |
(num_workers-1).times do | |
run "tmux split-window -t #{tmux_session}:#{tmux_window} #{worker_cmd}" | |
end | |
# empty block to silence output -----------------------------------------v | |
run "tmux select-layout -t #{tmux_session}:#{tmux_window} even-vertical" do end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment