Skip to content

Instantly share code, notes, and snippets.

@pzskc383
Created September 2, 2013 14:23
Show Gist options
  • Save pzskc383/6413400 to your computer and use it in GitHub Desktop.
Save pzskc383/6413400 to your computer and use it in GitHub Desktop.
capistrano thingy to restart workers in tmux
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