Sha256: 2c26dc19aed1b88694d42990b5915a5ec079f6adce5622bde5cbd4ccd9fca77e
Contents?: true
Size: 1.1 KB
Versions: 7
Compression:
Stored size: 1.1 KB
Contents
module AppRb::Util MIN_PORT = 10_000 MAX_PORT = 50_000 def self.yellow(txt); "\e[0;33m#{txt}\e[0m"; end def self.red(txt); "\e[0;31m#{txt}\e[0m"; end def self.green(txt); "\e[0;32m#{txt}\e[0m"; end def self.blue(txt); "\e[0;34m#{txt}\e[0m"; end def self.do_it(cmd) puts "[exec] #{cmd}" system(cmd) unless $?.success? puts red("FATAL :(") exit end end def self.just_cmd(cmd, skip_exit_status = false) puts "[exec] #{cmd}" output = `#{cmd}` if $?.success? || skip_exit_status output.strip else puts red(output) puts red("FATAL :(") exit end end def self.compare_versions(a, b) parse = proc { |v| v.split(".", 3).map(&:to_i) + [v.index("-dev") ? 1 : 0] } parse.call(a) <=> parse.call(b) end def self.get_free_port(user, host) port = nil 10.times do a = MIN_PORT + rand(MAX_PORT - MIN_PORT) if just_cmd("ssh #{user}@#{host} ss -ln src :#{a} | fgrep -c ':#{a}'", true) == "0" port = a break end end raise "Dont find free port :-((" unless port port end end
Version data entries
7 entries across 7 versions & 1 rubygems