Skip to content

Commit

Permalink
Improve get_zookeeper_admin_server_port
Browse files Browse the repository at this point in the history
  • Loading branch information
to-bar committed Jan 18, 2021
1 parent f52c3f4 commit 109a37a
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
require 'net/ssh'

def get_zookeeper_admin_server_port
default_port = 8080
config_file = "/opt/zookeeper/conf/zoo.cfg"
grep_cmd = "sudo -u zookeeper grep -Po '(?<=^admin\\.serverPort=)\\d+' #{config_file}"
port = ""

Net::SSH.start(ENV['TARGET_HOST'], ENV['user'], keys: [ENV['keypath']], :keys_only => true) do |ssh|
ssh.exec!(grep_cmd) do |channel, stream, data|
port << data if stream == :stdout && /^[0-9]+$/.match(data)
end
result = Specinfra.backend.run_command(grep_cmd)
if /^[0-9]+$/.match?(result.stdout)
port = result.stdout.chomp.to_i
else
port = default_port
end

return port.empty? ? default_port : port.to_i
return port
end

0 comments on commit 109a37a

Please sign in to comment.