Commit 12b4bb5946e6f43962a2161711e672facce1c1f4
1 parent
84465576
Exists in
master
and in
4 other branches
Make gitlab:env:info task more robust
Closes #2213
Showing
1 changed file
with
39 additions
and
21 deletions
Show diff stats
lib/tasks/gitlab/info.rake
| 1 | namespace :gitlab do | 1 | namespace :gitlab do |
| 2 | namespace :env do | 2 | namespace :env do |
| 3 | desc "GITLAB | Show information about GitLab and its environment" | 3 | desc "GITLAB | Show information about GitLab and its environment" |
| 4 | - task :info => :environment do | 4 | + task info: :environment do |
| 5 | 5 | ||
| 6 | # check which OS is running | 6 | # check which OS is running |
| 7 | - if Kernel.system('lsb_release > /dev/null 2>&1') | ||
| 8 | - os_name = `lsb_release -irs` | ||
| 9 | - elsif File.exists?('/etc/system-release') && File.readable?('/etc/system-release') | ||
| 10 | - os_name = File.read('/etc/system-release') | ||
| 11 | - elsif File.exists?('/etc/debian_version') && File.readable?('/etc/debian_version') | ||
| 12 | - debian_version = File.read('/etc/debian_version') | ||
| 13 | - os_name = "Debian #{debian_version}" | ||
| 14 | - end | ||
| 15 | - os_name = os_name.gsub(/\n/, '') | 7 | + os_name = run("lsb_release -irs") |
| 8 | + os_name ||= if File.readable?('/etc/system-release') | ||
| 9 | + File.read('/etc/system-release') | ||
| 10 | + end | ||
| 11 | + os_name ||= if File.readable?('/etc/debian_version') | ||
| 12 | + debian_version = File.read('/etc/debian_version') | ||
| 13 | + "Debian #{debian_version}" | ||
| 14 | + end | ||
| 15 | + os_name.squish! | ||
| 16 | 16 | ||
| 17 | # check if there is an RVM environment | 17 | # check if there is an RVM environment |
| 18 | - m, rvm_version = `rvm --version`.match(/rvm ([\d\.]+) /).to_a | 18 | + rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s) |
| 19 | + # check Gem version | ||
| 20 | + gem_version = run("gem --version") | ||
| 19 | # check Bundler version | 21 | # check Bundler version |
| 20 | - m, bunder_version = `bundle --version`.match(/Bundler version ([\d\.]+)/).to_a | 22 | + bunder_version = run_and_match("bundle --version", /[\d\.]+/).try(:to_s) |
| 21 | # check Bundler version | 23 | # check Bundler version |
| 22 | - m, rake_version = `rake --version`.match(/rake, version ([\d\.]+)/).to_a | 24 | + rake_version = run_and_match("rake --version", /[\d\.]+/).try(:to_s) |
| 23 | 25 | ||
| 24 | puts "" | 26 | puts "" |
| 25 | puts "System information".yellow | 27 | puts "System information".yellow |
| 26 | - puts "System:\t\t#{os_name}" | 28 | + puts "System:\t\t#{os_name || "unknown".red}" |
| 27 | puts "Current User:\t#{`whoami`}" | 29 | puts "Current User:\t#{`whoami`}" |
| 28 | puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" | 30 | puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" |
| 29 | puts "RVM Version:\t#{rvm_version}" if rvm_version.present? | 31 | puts "RVM Version:\t#{rvm_version}" if rvm_version.present? |
| 30 | - puts "Ruby Version:\t#{ENV['RUBY_VERSION']}" | ||
| 31 | - puts "Gem Version:\t#{`gem --version`}" | ||
| 32 | - puts "Bundler Version:#{bunder_version}" | ||
| 33 | - puts "Rake Version:\t#{rake_version}" | 32 | + puts "Ruby Version:\t#{ENV['RUBY_VERSION'] || "unknown".red}" |
| 33 | + puts "Gem Version:\t#{gem_version || "unknown".red}" | ||
| 34 | + puts "Bundler Version:#{bunder_version || "unknown".red}" | ||
| 35 | + puts "Rake Version:\t#{rake_version || "unknown".red}" | ||
| 34 | 36 | ||
| 35 | 37 | ||
| 36 | # check database adapter | 38 | # check database adapter |
| @@ -61,13 +63,11 @@ namespace :gitlab do | @@ -61,13 +63,11 @@ namespace :gitlab do | ||
| 61 | gitolite_version_file = "#{Gitlab.config.git_base_path}/../gitolite/src/VERSION" | 63 | gitolite_version_file = "#{Gitlab.config.git_base_path}/../gitolite/src/VERSION" |
| 62 | if File.exists?(gitolite_version_file) && File.readable?(gitolite_version_file) | 64 | if File.exists?(gitolite_version_file) && File.readable?(gitolite_version_file) |
| 63 | gitolite_version = File.read(gitolite_version_file) | 65 | gitolite_version = File.read(gitolite_version_file) |
| 64 | - else | ||
| 65 | - gitolite_version = 'unknown' | ||
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | puts "" | 68 | puts "" |
| 69 | puts "Gitolite information".yellow | 69 | puts "Gitolite information".yellow |
| 70 | - puts "Version:\t#{gitolite_version}" | 70 | + puts "Version:\t#{gitolite_version || "unknown".red}" |
| 71 | puts "Admin URI:\t#{Gitlab.config.gitolite_admin_uri}" | 71 | puts "Admin URI:\t#{Gitlab.config.gitolite_admin_uri}" |
| 72 | puts "Admin Key:\t#{Gitlab.config.gitolite_admin_key}" | 72 | puts "Admin Key:\t#{Gitlab.config.gitolite_admin_key}" |
| 73 | puts "Repositories:\t#{Gitlab.config.git_base_path}" | 73 | puts "Repositories:\t#{Gitlab.config.git_base_path}" |
| @@ -75,5 +75,23 @@ namespace :gitlab do | @@ -75,5 +75,23 @@ namespace :gitlab do | ||
| 75 | puts "Git:\t\t#{Gitlab.config.git.path}" | 75 | puts "Git:\t\t#{Gitlab.config.git.path}" |
| 76 | 76 | ||
| 77 | end | 77 | end |
| 78 | + | ||
| 79 | + | ||
| 80 | + # Helper methods | ||
| 81 | + | ||
| 82 | + # Runs the given command and matches the output agains the given RegExp | ||
| 83 | + def run_and_match(command, regexp) | ||
| 84 | + run(command).try(:match, regexp) | ||
| 85 | + end | ||
| 86 | + | ||
| 87 | + # Runs the given command | ||
| 88 | + # | ||
| 89 | + # Returns nil if the command was not found | ||
| 90 | + # Returns the output of the command otherwise | ||
| 91 | + def run(command) | ||
| 92 | + unless `#{command} 2>/dev/null`.blank? | ||
| 93 | + `#{command}` | ||
| 94 | + end | ||
| 95 | + end | ||
| 78 | end | 96 | end |
| 79 | end | 97 | end |