smart_proxy_discovery_image 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33b1e050b42bfdaa738931d647c63a8a57ba82d264770fe3713a377ee8d26761
4
- data.tar.gz: 3c7f7b8d0ec6a82eff559184537c1d207fd317d0e83ea4e91f86cac2100758b2
3
+ metadata.gz: 01103d93b909fdfc22ba01c37dd7061affb9d0440e35e041c3333c2884edaf37
4
+ data.tar.gz: b827937012ce424a99fe4c0f1d3bb756f996971a8c496d46bbfdcf69a1deb6b2
5
5
  SHA512:
6
- metadata.gz: 79c394795be0c33935ef82f2396f77fefe8158a151501235544ae5ec6781cb7b31431477e1daa96ede830e8a8dd7a3deed9375b17a44b0c8c7336bfc683ea60c
7
- data.tar.gz: c11681c80e5381cc7a0494497dd9e19337b768b404cd47395f77e81503e38ec4d527ddafe6c7d68dc8881fa1da2079dc35485cc84408bd7f847050a087ae3de3
6
+ metadata.gz: e30242f64d5d36ab550a2ded89f3d700a4ce324d296e4243486389c2319a9d30a8c81b1830f50e285b7894609d15de8edaf554d4e5108d39103b8eb01fe1874b
7
+ data.tar.gz: 4e2298339d4802460eb7f3f0fa08698bf76a034860d0944039aa690dad062c703d10cf4a4fdd60eed8242ceb9104ec011e0f1684d7c302a2acdfa179b373985f
@@ -24,31 +24,36 @@ module Proxy::DiscoveryImage
24
24
  rescue JSON::ParserError
25
25
  log_halt 500, "Unable to parse kexec JSON input: #{body_data}"
26
26
  end
27
- logger.debug "Downloading: #{data['kernel']}"
28
- if ::Proxy::HttpDownload.new(data['kernel'], '/tmp/vmlinuz').start.join != 0
29
- log_halt 500, "cannot download kernel for kexec!"
30
- end
31
- logger.debug "Downloading: #{data['initram']}"
32
- if ::Proxy::HttpDownload.new(data['initram'], '/tmp/initrd.img').start.join != 0
33
- log_halt 500, "cannot download initram for kexec!"
34
- end
35
- run_after_response 2, kexec, "--debug", "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz", *data['extra']
27
+ run_after_response data, 2, kexec, "--debug", "--force", "--append=#{data['append']}", "--initrd=/tmp/initrd.img", "/tmp/vmlinuz", *data['extra']
36
28
  { :result => true }.to_json
37
29
  end
38
30
 
39
31
 
40
32
  # Execute command in a separate thread after 5 seconds to give the server some
41
33
  # time to finish the request. Does *not* execute via a shell.
42
- def run_after_response(seconds, *command)
43
- logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
34
+ def run_after_response(data, seconds, *command)
44
35
  Thread.start do
45
36
  begin
46
- sleep seconds
47
- logger.debug "Power API executing: #{command.inspect}"
48
- if (sudo = which('sudo'))
49
- status = system(sudo, *command)
50
- else
51
- logger.warn "sudo binary was not found"
37
+ # download kernel and initramdisk
38
+ logger.debug "Downloading: #{data['kernel']}"
39
+ vmlinuz_thread = ::Proxy::HttpDownload.new(data['kernel'], '/tmp/vmlinuz').start
40
+ logger.error("vmlinuz is still downloading, ignored") unless vmlinuz_thread
41
+ logger.error("cannot download vmlinuz for kexec") unless vmlinuz_thread.join == 0
42
+ logger.debug "Downloading: #{data['initram']}"
43
+ initrd_thread = ::Proxy::HttpDownload.new(data['initram'], '/tmp/initrd.img').start
44
+ logger.error("initrd.img is still downloading, ignored") unless initrd_thread
45
+ logger.error("cannot download initrd.img for kexec") unless initrd_thread.join == 0
46
+ # wait few seconds just in case the download was fast and perform kexec
47
+ # only perform kexec when both locks were available to prevent subsequent request while downloading
48
+ if vmlinuz_thread && initrd_thread
49
+ logger.debug "Power API scheduling in #{seconds} seconds: #{command.inspect}"
50
+ sleep seconds
51
+ logger.debug "Power API executing: #{command.inspect}"
52
+ if (sudo = which('sudo'))
53
+ status = system(sudo, *command)
54
+ else
55
+ logger.warn "sudo binary was not found"
56
+ end
52
57
  end
53
58
  # only report errors
54
59
  logger.warn "The attempted command failed with code #{$?.exitstatus}" unless status
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module DiscoveryImage
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_discovery_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Zapletal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Smart Proxy plugin providing Image API on discovered nodes. This plugin is only