From 682cc3585858408a35236420d2303eaa843a5354 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 5 May 2020 14:11:35 -0400 Subject: [PATCH 1/3] lha bug fixes - commands are written in bash, so the ssh commands are now specifying bash to support users who have different login shells. - -l given to pstree for long output becuase without it, it cuts off needed output. --- .../job/adapters/linux_host/launcher.rb | 20 +++++++++---------- spec/job/adapters/linux_host/launcher_spec.rb | 11 ++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/ood_core/job/adapters/linux_host/launcher.rb b/lib/ood_core/job/adapters/linux_host/launcher.rb index 366f84a85..21ac688a6 100644 --- a/lib/ood_core/job/adapters/linux_host/launcher.rb +++ b/lib/ood_core/job/adapters/linux_host/launcher.rb @@ -57,7 +57,7 @@ def initialize( # @param hostname [#to_s] The hostname to submit the work to # @param script [OodCore::Job::Script] The script object defining the work def start_remote_session(script) - cmd = ssh_cmd(submit_host(script)) + cmd = ssh_cmd(submit_host(script), ['/usr/bin/env', 'bash']) session_name = unique_session_name output = call(*cmd, stdin: wrapped_script(script, session_name)) @@ -67,13 +67,13 @@ def start_remote_session(script) end def stop_remote_session(session_name, hostname) - cmd = ssh_cmd(hostname) + cmd = ssh_cmd(hostname, ['/usr/bin/env', 'bash']) kill_cmd = <<~SCRIPT # Get the tmux pane PID for the target session pane_pid=$(tmux list-panes -aF '\#{session_name} \#{pane_pid}' | grep '#{session_name}' | cut -f 2 -d ' ') # Find the Singularity sinit PID child of the pane process - pane_sinit_pid=$(pstree -p "$pane_pid" | grep -o 'sinit([[:digit:]]*' | grep -o '[[:digit:]]*') + pane_sinit_pid=$(pstree -p -l "$pane_pid" | grep -o 'sinit([[:digit:]]*' | grep -o '[[:digit:]]*') # Kill sinit which stops both Singularity-based processes and the tmux session kill "$pane_sinit_pid" SCRIPT @@ -116,27 +116,27 @@ def call(cmd, *args, env: {}, stdin: "") s.success? ? o : raise(Error, e) end - # The SSH invocation to send a command + # The SSH invocation to send the command you pass into cmd (Array) # -t Force pseudo-terminal allocation (required to allow tmux to run) # -o BatchMode=yes (set mode to be non-interactive) # if ! strict_host_checking # -o UserKnownHostsFile=/dev/null (do not update the user's known hosts file) # -o StrictHostKeyChecking=no (do no check the user's known hosts file) - def ssh_cmd(destination_host) + def ssh_cmd(destination_host, cmd) if strict_host_checking [ 'ssh', '-t', '-o', 'BatchMode=yes', - "#{username}@#{destination_host}" - ] + "#{username}@#{destination_host}", + ].concat(cmd) else [ 'ssh', '-t', '-o', 'BatchMode=yes', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', - "#{username}@#{destination_host}" - ] + "#{username}@#{destination_host}", + ].concat(cmd) end end @@ -245,7 +245,7 @@ def list_remote_tmux_session(destination_host) ['#{session_name}', '#{session_created}', '#{pane_pid}'].join(UNIT_SEPARATOR) ) keys = [:session_name, :session_created, :session_pid] - cmd = ssh_cmd(destination_host) + ['tmux', 'list-panes', '-aF', format_str] + cmd = ssh_cmd(destination_host, ['tmux', 'list-panes', '-aF', format_str]) call(*cmd).split( "\n" diff --git a/spec/job/adapters/linux_host/launcher_spec.rb b/spec/job/adapters/linux_host/launcher_spec.rb index cff39d50e..4c5040176 100644 --- a/spec/job/adapters/linux_host/launcher_spec.rb +++ b/spec/job/adapters/linux_host/launcher_spec.rb @@ -207,15 +207,17 @@ def content describe "#ssh_cmd" do let(:username) { Etc.getlogin } context "when strict_host_checking is true" do - let(:ssh_cmd) { subject.send(:ssh_cmd, 'remote_host') } + let(:ssh_cmd) { subject.send(:ssh_cmd, 'remote_host', ['/bin/bash']) } it "uses the correct SSH options" do - expect(ssh_cmd).to eq(['ssh', '-t', '-o', 'BatchMode=yes', "#{username}@remote_host"]) + expect(ssh_cmd).to eq(['ssh', '-t', '-o', 'BatchMode=yes', "#{username}@remote_host", '/bin/bash']) end end context "when strict_host_checking is false" do - let(:ssh_cmd) { described_class.new(**opts.merge({strict_host_checking: false})).send(:ssh_cmd, 'remote_host') } + let(:ssh_cmd) { + described_class.new(**opts.merge({strict_host_checking: false})).send(:ssh_cmd, 'remote_host', ['/bin/bash']) + } it "uses the correct SSH options" do expect(ssh_cmd).to eq([ @@ -223,7 +225,8 @@ def content '-o', 'BatchMode=yes', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', - "#{username}@remote_host" + "#{username}@remote_host", + "/bin/bash" ]) end end From 34571976ed90e3c89c84b01d3e5199ba55f437c2 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 5 May 2020 14:38:16 -0400 Subject: [PATCH 2/3] rm trailing commas --- lib/ood_core/job/adapters/linux_host/launcher.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ood_core/job/adapters/linux_host/launcher.rb b/lib/ood_core/job/adapters/linux_host/launcher.rb index 21ac688a6..d5e688142 100644 --- a/lib/ood_core/job/adapters/linux_host/launcher.rb +++ b/lib/ood_core/job/adapters/linux_host/launcher.rb @@ -127,7 +127,7 @@ def ssh_cmd(destination_host, cmd) [ 'ssh', '-t', '-o', 'BatchMode=yes', - "#{username}@#{destination_host}", + "#{username}@#{destination_host}" ].concat(cmd) else [ @@ -135,7 +135,7 @@ def ssh_cmd(destination_host, cmd) '-o', 'BatchMode=yes', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', - "#{username}@#{destination_host}", + "#{username}@#{destination_host}" ].concat(cmd) end end From f53f2f14dd2e3ec81b635fbc438557f09f5617d7 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 5 May 2020 15:03:19 -0400 Subject: [PATCH 3/3] reword ssh_cmd comment --- lib/ood_core/job/adapters/linux_host/launcher.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ood_core/job/adapters/linux_host/launcher.rb b/lib/ood_core/job/adapters/linux_host/launcher.rb index d5e688142..8b8117028 100644 --- a/lib/ood_core/job/adapters/linux_host/launcher.rb +++ b/lib/ood_core/job/adapters/linux_host/launcher.rb @@ -116,12 +116,16 @@ def call(cmd, *args, env: {}, stdin: "") s.success? ? o : raise(Error, e) end - # The SSH invocation to send the command you pass into cmd (Array) + # The full command to ssh into the destination host and execute the command. + # SSH options include: # -t Force pseudo-terminal allocation (required to allow tmux to run) # -o BatchMode=yes (set mode to be non-interactive) # if ! strict_host_checking # -o UserKnownHostsFile=/dev/null (do not update the user's known hosts file) # -o StrictHostKeyChecking=no (do no check the user's known hosts file) + # + # @param destination_host [#to_s] the destination host you wish to ssh into + # @param cmd [Array<#to_s>] the command to be executed on the destination host def ssh_cmd(destination_host, cmd) if strict_host_checking [