enviroblyd 0.4.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/enviroblyd +9 -1
- data/lib/enviroblyd/command.rb +7 -1
- data/lib/enviroblyd/daemon.rb +24 -16
- data/lib/enviroblyd/version.rb +1 -1
- data/lib/enviroblyd/web.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf14c9c81dfe5bf5842d0cfca53466605c2c053149096a74c955a506132ae30a
|
4
|
+
data.tar.gz: 45c8f5812463f757a9a56ab906d1a15e61fb3ed5ae6c84fc123b86b12e887f74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2c0a0d8077062a6149ad420e2e1a3769bc5ce16c47815bf65f4b96ab3ef15f5c7e3d1f93c5eb7ba862e822dbbb8cfb39c2c42122a823298e54e9a9c82e314cc
|
7
|
+
data.tar.gz: c82f027d69d99d30a3aa17b51adc6ed26e0474910aa89041747091193ddcd2ec8c2bb548c91574a4bbfd8eeb429b679c7b351f5cfdc5be71ae84e47ade290034
|
data/bin/enviroblyd
CHANGED
data/lib/enviroblyd/command.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "open3"
|
4
4
|
require "json"
|
5
|
+
require "zlib"
|
6
|
+
require "base64"
|
5
7
|
|
6
8
|
class Enviroblyd::Command
|
7
9
|
DEFAULT_TIMEOUT_SECONDS = 5 * 60
|
@@ -10,7 +12,7 @@ class Enviroblyd::Command
|
|
10
12
|
def initialize(message)
|
11
13
|
params = parse_message message
|
12
14
|
@url = params.fetch "url"
|
13
|
-
@script = params.fetch
|
15
|
+
@script = decode_and_decompress params.fetch("script")
|
14
16
|
@runtime = params.fetch "runtime", DEFAULT_RUNTIME
|
15
17
|
@timeout = params.fetch "timeout", DEFAULT_TIMEOUT_SECONDS
|
16
18
|
@stdout = @stderr = @exit_code = nil
|
@@ -54,4 +56,8 @@ class Enviroblyd::Command
|
|
54
56
|
rescue
|
55
57
|
nil
|
56
58
|
end
|
59
|
+
|
60
|
+
def decode_and_decompress(encoded_data)
|
61
|
+
Zlib::Inflate.inflate Base64.decode64(encoded_data)
|
62
|
+
end
|
57
63
|
end
|
data/lib/enviroblyd/daemon.rb
CHANGED
@@ -6,29 +6,25 @@ class Enviroblyd::Daemon
|
|
6
6
|
MAX_MESSAGE_SIZE = 6000 # bytes
|
7
7
|
PORT = ENV.fetch("ENVIROBLYD_PORT", 63106).to_i
|
8
8
|
|
9
|
-
def
|
9
|
+
def initialize
|
10
10
|
imds = Enviroblyd::IMDS.new
|
11
|
-
host = imds.private_ipv4
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(host)
|
17
|
-
@host = host
|
11
|
+
@host = imds.private_ipv4
|
12
|
+
@threads = []
|
13
|
+
@shutdown = false
|
18
14
|
end
|
19
15
|
|
20
16
|
def listen
|
21
|
-
server = TCPServer.new @host, PORT
|
17
|
+
@server = TCPServer.new @host, PORT
|
22
18
|
puts "Listening on #{@host}:#{PORT}"
|
23
19
|
Enviroblyd::Web.register
|
24
20
|
|
25
|
-
|
26
|
-
Thread.start(server.accept) do |client|
|
21
|
+
until @shutdown do
|
22
|
+
@threads << Thread.start(@server.accept) do |client|
|
27
23
|
message = client.recv(MAX_MESSAGE_SIZE)
|
28
24
|
command = Enviroblyd::Command.new message
|
29
25
|
|
30
26
|
unless command.valid?
|
31
|
-
|
27
|
+
puts "Invalid message received: #{message}"
|
32
28
|
client.puts "Invalid message"
|
33
29
|
next
|
34
30
|
end
|
@@ -38,11 +34,23 @@ class Enviroblyd::Daemon
|
|
38
34
|
command.run
|
39
35
|
ensure
|
40
36
|
client.close
|
41
|
-
command = nil
|
42
|
-
message = nil
|
43
|
-
client = nil
|
44
|
-
GC.start
|
45
37
|
end
|
38
|
+
|
39
|
+
delete_dead_threads
|
40
|
+
GC.start
|
41
|
+
GC.compact
|
46
42
|
end
|
47
43
|
end
|
44
|
+
|
45
|
+
def shutdown
|
46
|
+
@threads.each(&:join)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def delete_dead_threads
|
51
|
+
@threads.each do |thread|
|
52
|
+
next if thread.alive?
|
53
|
+
@threads.delete thread
|
54
|
+
end
|
55
|
+
end
|
48
56
|
end
|
data/lib/enviroblyd/version.rb
CHANGED
data/lib/enviroblyd/web.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require "net/http"
|
4
4
|
require "uri"
|
5
|
-
require "open3"
|
6
5
|
require "fileutils"
|
7
6
|
require "pathname"
|
8
7
|
require "json"
|
@@ -10,7 +9,6 @@ require "json"
|
|
10
9
|
class Enviroblyd::Web
|
11
10
|
USER_AGENT = "enviroblyd #{Enviroblyd::VERSION}"
|
12
11
|
CONTENT_TYPE = "application/json"
|
13
|
-
API_HOST = ENV.fetch("ENVIROBLYD_API_HOST", "envirobly.com")
|
14
12
|
WORKING_DIR = Pathname.new ENV.fetch("ENVIROBLYD_WORKING_DIR", "/var/envirobly/daemon")
|
15
13
|
INITIALIZED_FILE = WORKING_DIR.join "initialized"
|
16
14
|
|
@@ -33,8 +31,8 @@ class Enviroblyd::Web
|
|
33
31
|
|
34
32
|
def http(url, type: Net::HTTP::Get, params: nil, headers: {}, retry_interval: 3, retries: 10, backoff: :exponential, tries: 1)
|
35
33
|
if retries <= tries
|
36
|
-
|
37
|
-
|
34
|
+
puts "Retried #{url} #{tries} times. Aborting."
|
35
|
+
return
|
38
36
|
end
|
39
37
|
|
40
38
|
uri = URI(url)
|
@@ -56,7 +54,7 @@ class Enviroblyd::Web
|
|
56
54
|
|
57
55
|
if response == :retry || (500..599).include?(response.code.to_i)
|
58
56
|
sleep_time = (backoff == :exponential) ? (retry_interval * tries) : retry_interval
|
59
|
-
|
57
|
+
puts "Retry #{uri} in #{sleep_time}s"
|
60
58
|
sleep sleep_time
|
61
59
|
http(url, type:, params:, retry_interval:, retries:, backoff:, tries: (tries + 1))
|
62
60
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enviroblyd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|