braintree / runbook

A framework for gradual system automation
MIT License
730 stars 43 forks source link

tmux_command #32

Closed pitosalas closed 4 years ago

pitosalas commented 4 years ago

I am experimenting with tmux + runbook. Here's a script and an error that it produces. Maybe you can see what's wrong? What does unknown command: C-m mean? It looks like tmux is giving it but I don't know what's going on. Thanks!

#!/usr/bin/env ruby
require "runbook"
require_relative "rbenv"

runbook = Runbook.book "Uneven Layout" do
  layout [[
    {:left => 20, {name: :middle, runbook_pane: true} => 60, :right => 20},
    {bottom_left: 5, bottom_right: 5}
  ]]
  section "Run Primary" do
    step "run" do
      env({TWITTER_CONSUMER_KEY: TWTITER_CONSUMER_KEY,
           TWITTER_CONSUMER_SECRET: TWITTER_CONSUMER_SECRET,
           TWITTER_ACCESS_TOKEN: TWITTER_ACCESS_TOKEN,
           TWITTER_ACCESS_SECRET: TWITTER_ACCESS_SECRET})
      server "rails@" + PRIMARY_SERVER_IP
      tmux_command "pwd", :bottom_right
      tmux_command "/usr/bin/ruby soa_demo/soa_publisher_node.rb;", :bottom_left
    end
  end
end

if __FILE__ == $0
  Runbook::Runner.new(runbook).run(start_at: 1, auto: true)
else
  runbook
end

This produces this output:

~/m/soa_demo (master=) ruby runbook/play.rb
Executing Uneven Layout...

Section 1: Run Primary

Step 1.1: run

unknown command: C-m

Killing all opened tmux panes...
~/m/soa_demo (master *=)

I assumed that the

server "rails@" + PRIMARY_SERVER+IP"

statement would cause the following tmux commands to be sent to that server. Or do I need to actually put an ssh command in the tmux_command itself, like this?

tmux_command 'ssh "rails@" + PRIMARY_SERVER_IP + '/usr/bin/ruby soa_demo/soa_publisher_node.rb;' :bottom_left

Thanks for your help. I'm kind of stuck at this point waiting for your comments!

pblesi commented 4 years ago

This is how tmux_commands interact with tmux itself: https://github.com/braintree/runbook/blob/799c2e2869423ed1af3d56e6c2ba5459ac1143a9/lib/runbook/helpers/tmux_helper.rb#L23

C-m is a return character that is sent to the tmux pane. The semicolon is getting interpreted by send-keys. To alleviate this you can escape the semicolon as in:

tmux_command "/usr/bin/ruby soa_demo/soa_publisher_node.rb\\;", :bottom_left

server, env, etc do not apply to tmux commands. That is, all tmux_commands are executed locally, so you would need to include ssh rails@#{PRIMARY_SERVER_IP}...

pitosalas commented 4 years ago

Thanks!!