smart_proxy_remote_execution_ssh 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db736b4bf0a21a18f335774778041f20480f18b886669d87c9d0f902e749eb14
4
- data.tar.gz: 49741c279188b7371c212949d77cb8ebe488eccde6198018c41853bdad673f33
3
+ metadata.gz: 88b0285639f42712b4f588b01c4830b7155d971dc0677a4cf3a04e2557b742a0
4
+ data.tar.gz: a3b3af8bb1bf183a4156af74b758120f1039de80add807e1cea8713bcd6e982e
5
5
  SHA512:
6
- metadata.gz: 92b94f0e609c6f5485f1519a6f853f74b75de8e1efec6f93bcf52519af8f585eb6a1189c547ce606434bdccf16764704d06c4d7bf0aa42b83a990a599585cce7
7
- data.tar.gz: 4b0bc9999579dda06bcbdee9d0e6e422e67441e8fc82af6ea9064d8aec843a505a8a6505ba267bfdea514f8ba6ceb772ac06db5d4b0b2db27a1268a37033231f
6
+ metadata.gz: 12bfc09f6535367e6f090b0d0401b57e9395bd44b3c41603ec06279930bd1c1f48ef24d6a8088999aa323bf42901e9dd9b0460dfb634712b2cd4119374c377ee
7
+ data.tar.gz: 6715dbc41c631447a1e2817e4e8ab289230258a49b874f837d7e529bdb6e7f05ddae670389b2a2e3466a02598ee9238dfbb3ce13ea19c6e47a6fbf9624a88c41
@@ -118,7 +118,6 @@ module Proxy::RemoteExecution::Ssh::Runners
118
118
  @first_execution = options.fetch(:first_execution, false)
119
119
  @user_method = user_method
120
120
  @options = options
121
- @supports_unshare = false
122
121
  end
123
122
 
124
123
  def self.build(options, suspended_action:)
@@ -150,7 +149,6 @@ module Proxy::RemoteExecution::Ssh::Runners
150
149
  @connection = MultiplexedSSHConnection.new(@options.merge(:id => @id), logger: logger)
151
150
  @connection.establish!
152
151
  preflight_checks
153
- detect_capabilities
154
152
  prepare_start
155
153
  script = initialization_script
156
154
  logger.debug("executing script:\n#{indent_multiline(script)}")
@@ -164,16 +162,6 @@ module Proxy::RemoteExecution::Ssh::Runners
164
162
  run_async(*args)
165
163
  end
166
164
 
167
- def detect_capabilities
168
- script = cp_script_to_remote("#!/bin/sh\nexec #{UNSHARE_PREFIX} true")
169
- begin
170
- ensure_remote_command(script)
171
- @supports_unshare = true
172
- rescue; end
173
- # The path should already be escaped
174
- ensure_remote_command("rm #{script}")
175
- end
176
-
177
165
  def preflight_checks
178
166
  script = cp_script_to_remote("#!/bin/sh\nexec true")
179
167
  ensure_remote_command(script,
@@ -195,27 +183,32 @@ module Proxy::RemoteExecution::Ssh::Runners
195
183
  @output_path = File.join(File.dirname(@remote_script), 'output')
196
184
  @exit_code_path = File.join(File.dirname(@remote_script), 'exit_code')
197
185
  @pid_path = File.join(File.dirname(@remote_script), 'pid')
186
+ su_method = @user_method.instance_of?(SuUserMethod)
187
+ wrapper = <<~SCRIPT
188
+ if [ "$1" == "inner" ]; then
189
+ echo \$$ > #{@pid_path}
190
+ (
191
+ #{@user_method.cli_command_prefix}#{su_method ? "'exec #{@remote_script} < /dev/null '" : "#{@remote_script} < /dev/null"}
192
+ echo \$? >#{@exit_code_path}
193
+ ) | tee #{@output_path}
194
+ else
195
+ UNSHARE=''
196
+ if #{UNSHARE_PREFIX} true >/dev/null 2>/dev/null; then
197
+ UNSHARE='#{UNSHARE_PREFIX}'
198
+ fi
199
+ exec $UNSHARE "$0" inner
200
+ fi
201
+ SCRIPT
198
202
  @remote_script_wrapper = upload_data(
199
- "echo $$ > #{@pid_path}; exec #{@supports_unshare ? UNSHARE_PREFIX : ''} \"$@\";",
203
+ wrapper,
200
204
  File.join(File.dirname(@remote_script), 'script-wrapper'),
201
205
  555)
202
206
  end
203
207
 
204
208
  # the script that initiates the execution
205
209
  def initialization_script
206
- su_method = @user_method.instance_of?(SuUserMethod)
207
210
  # pipe the output to tee while capturing the exit code in a file
208
- <<~SCRIPT
209
- sh <<EOF | /usr/bin/tee #{@output_path}
210
- #{@remote_script_wrapper} #{@user_method.cli_command_prefix}#{su_method ? "'#{@remote_script} < /dev/null '" : "#{@remote_script} < /dev/null"}
211
- echo \\$?>#{@exit_code_path}
212
- EOF
213
- if [ -f #{@exit_code_path} ] && [ $(wc -l < #{@exit_code_path}) -gt 0 ]; then
214
- exit $(cat #{@exit_code_path})
215
- else
216
- exit 1
217
- fi
218
- SCRIPT
211
+ @remote_script_wrapper
219
212
  end
220
213
 
221
214
  def refresh
@@ -227,7 +220,7 @@ module Proxy::RemoteExecution::Ssh::Runners
227
220
 
228
221
  def kill
229
222
  if @process_manager&.started?
230
- run_sync("pkill -P $(cat #{@pid_path})")
223
+ run_sync("kill $(cat #{@pid_path})")
231
224
  else
232
225
  logger.debug('connection closed')
233
226
  end
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module RemoteExecution
3
3
  module Ssh
4
- VERSION = '0.11.0'
4
+ VERSION = '0.11.1'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_remote_execution_ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-10 00:00:00.000000000 Z
11
+ date: 2024-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler