blackstack-nodes 1.2.14 → 1.2.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blackstack-nodes.rb +30 -14
- 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: 7030c06d185e9257db6bcf42deadcbcc1ac609f79140b8ce63f73f5368232144
|
4
|
+
data.tar.gz: adc175dd676a9b3940454342016ec82b96d771f885f6ca92d26f317d5f722331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d3807f8df44577cff9d4b57329ad28e2a6216bce5566a178893ed390c2b6f943b45ddbd561b2fa793506010a586108468eb0e05c53e55ce81f36c74089bb2eb
|
7
|
+
data.tar.gz: 3cf124a33af4fcffaa3fd2b642fe561774d296cc629cc67d0e9bb865425eb5688fa13bf0e68b89a0272c1c7337b1fb06490b4669c86165bd421bbc88ef68d37a
|
data/lib/blackstack-nodes.rb
CHANGED
@@ -117,31 +117,47 @@ module BlackStack
|
|
117
117
|
self.ssh.close
|
118
118
|
end
|
119
119
|
|
120
|
+
# Execute a command on the remote server and return the output.
|
121
|
+
# If the exit code of the command is not zero, an exception is raised, with the messages pushed into the stderr.
|
122
|
+
# If the exit code of the command is zero, the messages pushed into the stdout are returned.
|
123
|
+
#
|
124
|
+
# IMPORTANT: Messages pushed into stderr re not always error.
|
125
|
+
# Reference:
|
126
|
+
# - How to stop git from writing non-errors to stderr ?
|
127
|
+
# - https://stackoverflow.com/questions/57016157/how-to-stop-git-from-writing-non-errors-to-stderr
|
128
|
+
#
|
120
129
|
def exec(
|
121
130
|
command,
|
122
|
-
output_file: "
|
123
|
-
error_file: "
|
131
|
+
output_file: "$HOME/.bash-command-stdout-buffer",
|
132
|
+
error_file: "$HOME/.bash-command-stderr-buffer",
|
133
|
+
exit_code_file: "$HOME/.bash-command-exit-code"
|
124
134
|
)
|
125
|
-
# Construct the remote command with redirection for stdout and
|
126
|
-
remote_command = "#{command} > #{output_file} 2> #{error_file}"
|
135
|
+
# Construct the remote command with redirection for stdout, stderr, and capturing exit code
|
136
|
+
remote_command = "#{command} > #{output_file} 2> #{error_file}; echo $? > #{exit_code_file}"
|
127
137
|
|
128
|
-
# Execute the command on the remote server
|
129
|
-
self.ssh.exec!("truncate -s 0 #{output_file} #{error_file}
|
138
|
+
# Execute the command on the remote server, truncating output, error, and exit code files
|
139
|
+
self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} #{exit_code_file}")
|
130
140
|
|
141
|
+
# Execute the command on the remote server, truncating output, error, and exit code files
|
142
|
+
self.ssh.exec!(remote_command)
|
143
|
+
|
144
|
+
# Retrieve the exit code
|
145
|
+
exit_code = self.ssh.exec!("cat #{exit_code_file}").to_s.chomp.to_i
|
146
|
+
|
131
147
|
# Retrieve the content of the error file from the remote server
|
132
148
|
error_content = self.ssh.exec!("cat #{error_file}").to_s.chomp
|
133
|
-
|
134
|
-
# Check if the
|
135
|
-
|
149
|
+
|
150
|
+
# Check if the exit code is not zero
|
151
|
+
if exit_code != 0
|
136
152
|
# Raise an exception with the error message
|
137
|
-
raise "Command failed with
|
153
|
+
raise "Command failed with exit code #{exit_code}:\n#{error_content}"
|
138
154
|
end
|
139
|
-
|
155
|
+
|
140
156
|
# Retrieve and return the content of the output file from the remote server
|
141
|
-
#
|
157
|
+
# Truncate any trailing newline character
|
142
158
|
self.ssh.exec!("cat #{output_file}").to_s.chomp
|
143
|
-
end
|
144
|
-
|
159
|
+
end # def exec
|
160
|
+
|
145
161
|
def reboot()
|
146
162
|
tries = 0
|
147
163
|
max_tries = 20
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackstack-nodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|