Commit 2b816075dc71dfe8f6f9e5349fdff7f03ad9dad0
1 parent
a9dcfd85
Exists in
spb-stable
and in
3 other branches
Replace backticks with Gitlab::Popen
Showing
8 changed files
with
33 additions
and
24 deletions
Show diff stats
app/controllers/admin/background_jobs_controller.rb
| 1 | class Admin::BackgroundJobsController < Admin::ApplicationController | 1 | class Admin::BackgroundJobsController < Admin::ApplicationController |
| 2 | def show | 2 | def show |
| 3 | - @sidekiq_processes = `ps -U #{Settings.gitlab.user} -o euser,pid,pcpu,pmem,stat,start,command | grep sidekiq | grep -v grep` | 3 | + ps_output, _ = Gitlab::Popen.popen(%W(ps -U #{Settings.gitlab.user} -o euser,pid,pcpu,pmem,stat,start,command)) |
| 4 | + @sidekiq_processes = ps_output.split("\n").grep(/sidekiq/) | ||
| 4 | end | 5 | end |
| 5 | end | 6 | end |
config/initializers/2_app.rb
| 1 | module Gitlab | 1 | module Gitlab |
| 2 | VERSION = File.read(Rails.root.join("VERSION")).strip | 2 | VERSION = File.read(Rails.root.join("VERSION")).strip |
| 3 | - REVISION = `git log --pretty=format:'%h' -n 1` | 3 | + REVISION = Gitlab::Popen.popen(%W(git log --pretty=format:%h -n 1)).first.chomp |
| 4 | 4 | ||
| 5 | def self.config | 5 | def self.config |
| 6 | Settings | 6 | Settings |
lib/backup/manager.rb
| @@ -8,7 +8,7 @@ module Backup | @@ -8,7 +8,7 @@ module Backup | ||
| 8 | s[:db_version] = "#{ActiveRecord::Migrator.current_version}" | 8 | s[:db_version] = "#{ActiveRecord::Migrator.current_version}" |
| 9 | s[:backup_created_at] = Time.now | 9 | s[:backup_created_at] = Time.now |
| 10 | s[:gitlab_version] = Gitlab::VERSION | 10 | s[:gitlab_version] = Gitlab::VERSION |
| 11 | - s[:tar_version] = %x{tar --version | head -1}.gsub(/\n/,"") | 11 | + s[:tar_version] = tar_version |
| 12 | 12 | ||
| 13 | Dir.chdir(Gitlab.config.backup.path) | 13 | Dir.chdir(Gitlab.config.backup.path) |
| 14 | 14 | ||
| @@ -98,5 +98,10 @@ module Backup | @@ -98,5 +98,10 @@ module Backup | ||
| 98 | exit 1 | 98 | exit 1 |
| 99 | end | 99 | end |
| 100 | end | 100 | end |
| 101 | + | ||
| 102 | + def tar_version | ||
| 103 | + tar_version, _ = Gitlab::Popen.popen(%W(tar --version)) | ||
| 104 | + tar_version.split("\n").first | ||
| 105 | + end | ||
| 101 | end | 106 | end |
| 102 | end | 107 | end |
lib/gitlab/logger.rb
| @@ -11,12 +11,14 @@ module Gitlab | @@ -11,12 +11,14 @@ module Gitlab | ||
| 11 | def self.read_latest | 11 | def self.read_latest |
| 12 | path = Rails.root.join("log", file_name) | 12 | path = Rails.root.join("log", file_name) |
| 13 | self.build unless File.exist?(path) | 13 | self.build unless File.exist?(path) |
| 14 | - logs = `tail -n 2000 #{path}`.split("\n") | 14 | + tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) |
| 15 | + tail_output.split("\n") | ||
| 15 | end | 16 | end |
| 16 | 17 | ||
| 17 | def self.read_latest_for filename | 18 | def self.read_latest_for filename |
| 18 | path = Rails.root.join("log", filename) | 19 | path = Rails.root.join("log", filename) |
| 19 | - logs = `tail -n 2000 #{path}`.split("\n") | 20 | + tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) |
| 21 | + tail_output.split("\n") | ||
| 20 | end | 22 | end |
| 21 | 23 | ||
| 22 | def self.build | 24 | def self.build |
lib/gitlab/upgrader.rb
| @@ -42,8 +42,9 @@ module Gitlab | @@ -42,8 +42,9 @@ module Gitlab | ||
| 42 | end | 42 | end |
| 43 | 43 | ||
| 44 | def latest_version_raw | 44 | def latest_version_raw |
| 45 | - git_tags = `git ls-remote --tags origin | grep tags\/v#{current_version.major}` | ||
| 46 | - git_tags = git_tags.lines.to_a.select { |version| version =~ /v\d\.\d\.\d\Z/ } | 45 | + remote_tags, _ = Gitlab::Popen.popen(%W(git ls-remote --tags origin)) |
| 46 | + git_tags = remote_tags.split("\n").grep(/tags\/v#{current_version.major}/) | ||
| 47 | + git_tags = git_tags.select { |version| version =~ /v\d\.\d\.\d\Z/ } | ||
| 47 | last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s | 48 | last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s |
| 48 | end | 49 | end |
| 49 | 50 |
lib/tasks/gitlab/check.rake
| @@ -168,7 +168,7 @@ namespace :gitlab do | @@ -168,7 +168,7 @@ namespace :gitlab do | ||
| 168 | def check_migrations_are_up | 168 | def check_migrations_are_up |
| 169 | print "All migrations up? ... " | 169 | print "All migrations up? ... " |
| 170 | 170 | ||
| 171 | - migration_status = `bundle exec rake db:migrate:status` | 171 | + migration_status, _ = Gitlab::Popen.popen(%W(bundle exec rake db:migrate:status)) |
| 172 | 172 | ||
| 173 | unless migration_status =~ /down\s+\d{14}/ | 173 | unless migration_status =~ /down\s+\d{14}/ |
| 174 | puts "yes".green | 174 | puts "yes".green |
| @@ -295,7 +295,7 @@ namespace :gitlab do | @@ -295,7 +295,7 @@ namespace :gitlab do | ||
| 295 | "user.email" => Gitlab.config.gitlab.email_from | 295 | "user.email" => Gitlab.config.gitlab.email_from |
| 296 | } | 296 | } |
| 297 | correct_options = options.map do |name, value| | 297 | correct_options = options.map do |name, value| |
| 298 | - run("git config --global --get #{name}").try(:squish) == value | 298 | + run(%W(git config --global --get #{name})).try(:squish) == value |
| 299 | end | 299 | end |
| 300 | 300 | ||
| 301 | if correct_options.all? | 301 | if correct_options.all? |
| @@ -628,7 +628,8 @@ namespace :gitlab do | @@ -628,7 +628,8 @@ namespace :gitlab do | ||
| 628 | end | 628 | end |
| 629 | 629 | ||
| 630 | def sidekiq_process_count | 630 | def sidekiq_process_count |
| 631 | - `ps ux`.scan(/sidekiq \d+\.\d+\.\d+/).count | 631 | + ps_ux, _ = Gitlab::Popen.popen(%W(ps ux)) |
| 632 | + ps_ux.scan(/sidekiq \d+\.\d+\.\d+/).count | ||
| 632 | end | 633 | end |
| 633 | end | 634 | end |
| 634 | 635 | ||
| @@ -739,7 +740,7 @@ namespace :gitlab do | @@ -739,7 +740,7 @@ namespace :gitlab do | ||
| 739 | 740 | ||
| 740 | def check_git_version | 741 | def check_git_version |
| 741 | required_version = Gitlab::VersionInfo.new(1, 7, 10) | 742 | required_version = Gitlab::VersionInfo.new(1, 7, 10) |
| 742 | - current_version = Gitlab::VersionInfo.parse(run("#{Gitlab.config.git.bin_path} --version")) | 743 | + current_version = Gitlab::VersionInfo.parse(run(%W(#{Gitlab.config.git.bin_path} --version))) |
| 743 | 744 | ||
| 744 | puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\"" | 745 | puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\"" |
| 745 | print "Git version >= #{required_version} ? ... " | 746 | print "Git version >= #{required_version} ? ... " |
lib/tasks/gitlab/info.rake
| @@ -4,20 +4,20 @@ namespace :gitlab do | @@ -4,20 +4,20 @@ namespace :gitlab do | ||
| 4 | task info: :environment do | 4 | task info: :environment do |
| 5 | 5 | ||
| 6 | # check if there is an RVM environment | 6 | # check if there is an RVM environment |
| 7 | - rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s) | 7 | + rvm_version = run_and_match(%W(rvm --version), /[\d\.]+/).try(:to_s) |
| 8 | # check Ruby version | 8 | # check Ruby version |
| 9 | - ruby_version = run_and_match("ruby --version", /[\d\.p]+/).try(:to_s) | 9 | + ruby_version = run_and_match(%W(ruby --version), /[\d\.p]+/).try(:to_s) |
| 10 | # check Gem version | 10 | # check Gem version |
| 11 | - gem_version = run("gem --version") | 11 | + gem_version = run(%W(gem --version)) |
| 12 | # check Bundler version | 12 | # check Bundler version |
| 13 | - bunder_version = run_and_match("bundle --version", /[\d\.]+/).try(:to_s) | 13 | + bunder_version = run_and_match(%W(bundle --version), /[\d\.]+/).try(:to_s) |
| 14 | # check Bundler version | 14 | # check Bundler version |
| 15 | - rake_version = run_and_match("rake --version", /[\d\.]+/).try(:to_s) | 15 | + rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s) |
| 16 | 16 | ||
| 17 | puts "" | 17 | puts "" |
| 18 | puts "System information".yellow | 18 | puts "System information".yellow |
| 19 | puts "System:\t\t#{os_name || "unknown".red}" | 19 | puts "System:\t\t#{os_name || "unknown".red}" |
| 20 | - puts "Current User:\t#{`whoami`}" | 20 | + puts "Current User:\t#{run(%W(whoami))}" |
| 21 | puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" | 21 | puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" |
| 22 | puts "RVM Version:\t#{rvm_version}" if rvm_version.present? | 22 | puts "RVM Version:\t#{rvm_version}" if rvm_version.present? |
| 23 | puts "Ruby Version:\t#{ruby_version || "unknown".red}" | 23 | puts "Ruby Version:\t#{ruby_version || "unknown".red}" |
lib/tasks/gitlab/task_helpers.rake
| @@ -28,7 +28,7 @@ namespace :gitlab do | @@ -28,7 +28,7 @@ namespace :gitlab do | ||
| 28 | # It will primarily use lsb_relase to determine the OS. | 28 | # It will primarily use lsb_relase to determine the OS. |
| 29 | # It has fallbacks to Debian, SuSE, OS X and systems running systemd. | 29 | # It has fallbacks to Debian, SuSE, OS X and systems running systemd. |
| 30 | def os_name | 30 | def os_name |
| 31 | - os_name = run("lsb_release -irs") | 31 | + os_name = run(%W(lsb_release -irs)) |
| 32 | os_name ||= if File.readable?('/etc/system-release') | 32 | os_name ||= if File.readable?('/etc/system-release') |
| 33 | File.read('/etc/system-release') | 33 | File.read('/etc/system-release') |
| 34 | end | 34 | end |
| @@ -39,7 +39,7 @@ namespace :gitlab do | @@ -39,7 +39,7 @@ namespace :gitlab do | ||
| 39 | os_name ||= if File.readable?('/etc/SuSE-release') | 39 | os_name ||= if File.readable?('/etc/SuSE-release') |
| 40 | File.read('/etc/SuSE-release') | 40 | File.read('/etc/SuSE-release') |
| 41 | end | 41 | end |
| 42 | - os_name ||= if os_x_version = run("sw_vers -productVersion") | 42 | + os_name ||= if os_x_version = run(%W(sw_vers -productVersion)) |
| 43 | "Mac OS X #{os_x_version}" | 43 | "Mac OS X #{os_x_version}" |
| 44 | end | 44 | end |
| 45 | os_name ||= if File.readable?('/etc/os-release') | 45 | os_name ||= if File.readable?('/etc/os-release') |
| @@ -80,13 +80,12 @@ namespace :gitlab do | @@ -80,13 +80,12 @@ namespace :gitlab do | ||
| 80 | # | 80 | # |
| 81 | # see also #run_and_match | 81 | # see also #run_and_match |
| 82 | def run(command) | 82 | def run(command) |
| 83 | - unless `#{command} 2>/dev/null`.blank? | ||
| 84 | - `#{command}` | ||
| 85 | - end | 83 | + output, _ = Gitlab::Popen.popen(command) |
| 84 | + output | ||
| 86 | end | 85 | end |
| 87 | 86 | ||
| 88 | def uid_for(user_name) | 87 | def uid_for(user_name) |
| 89 | - run("id -u #{user_name}").chomp.to_i | 88 | + run(%W(id -u #{user_name})).chomp.to_i |
| 90 | end | 89 | end |
| 91 | 90 | ||
| 92 | def gid_for(group_name) | 91 | def gid_for(group_name) |
| @@ -100,7 +99,7 @@ namespace :gitlab do | @@ -100,7 +99,7 @@ namespace :gitlab do | ||
| 100 | def warn_user_is_not_gitlab | 99 | def warn_user_is_not_gitlab |
| 101 | unless @warned_user_not_gitlab | 100 | unless @warned_user_not_gitlab |
| 102 | gitlab_user = Gitlab.config.gitlab.user | 101 | gitlab_user = Gitlab.config.gitlab.user |
| 103 | - current_user = run("whoami").chomp | 102 | + current_user = run(%W(whoami)).chomp |
| 104 | unless current_user == gitlab_user | 103 | unless current_user == gitlab_user |
| 105 | puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" | 104 | puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" |
| 106 | puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." | 105 | puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." |