Commit f1d8efb7700fb95b98924ffe2e65dd08f7f376c9
Exists in
spb-stable
and in
3 other branches
Merge branch 'shell_new_style' into 'master'
Use new style shell commands
Showing
14 changed files
with
66 additions
and
64 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,28 +42,33 @@ module Gitlab | @@ -42,28 +42,33 @@ 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 | ||
50 | def update_commands | 51 | def update_commands |
51 | { | 52 | { |
52 | - "Stash changed files" => "git stash", | ||
53 | - "Get latest code" => "git fetch", | ||
54 | - "Switch to new version" => "git checkout v#{latest_version}", | ||
55 | - "Install gems" => "bundle", | ||
56 | - "Migrate DB" => "bundle exec rake db:migrate RAILS_ENV=production", | ||
57 | - "Recompile assets" => "bundle exec rake assets:clean assets:precompile RAILS_ENV=production", | ||
58 | - "Clear cache" => "bundle exec rake cache:clear RAILS_ENV=production" | 53 | + "Stash changed files" => %W(git stash), |
54 | + "Get latest code" => %W(git fetch), | ||
55 | + "Switch to new version" => %W(git checkout v#{latest_version}), | ||
56 | + "Install gems" => %W(bundle), | ||
57 | + "Migrate DB" => %W(bundle exec rake db:migrate), | ||
58 | + "Recompile assets" => %W(bundle exec rake assets:clean assets:precompile), | ||
59 | + "Clear cache" => %W(bundle exec rake cache:clear) | ||
59 | } | 60 | } |
60 | end | 61 | end |
61 | 62 | ||
63 | + def env | ||
64 | + {'RAILS_ENV' => 'production'} | ||
65 | + end | ||
66 | + | ||
62 | def upgrade | 67 | def upgrade |
63 | update_commands.each do |title, cmd| | 68 | update_commands.each do |title, cmd| |
64 | puts title | 69 | puts title |
65 | - puts " -> #{cmd}" | ||
66 | - if system(cmd) | 70 | + puts " -> #{cmd.join(' ')}" |
71 | + if system(env, *cmd) | ||
67 | puts " -> OK" | 72 | puts " -> OK" |
68 | else | 73 | else |
69 | puts " -> FAILED" | 74 | puts " -> FAILED" |
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/generate_docs.rake
1 | namespace :gitlab do | 1 | namespace :gitlab do |
2 | desc "GITLAB | Generate sdocs for project" | 2 | desc "GITLAB | Generate sdocs for project" |
3 | task generate_docs: :environment do | 3 | task generate_docs: :environment do |
4 | - system("bundle exec sdoc -o doc/code app lib") | 4 | + system(*%W(bundle exec sdoc -o doc/code app lib)) |
5 | end | 5 | end |
6 | end | 6 | end |
7 | 7 |
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." |
lib/tasks/gitlab/test.rake
@@ -2,15 +2,15 @@ namespace :gitlab do | @@ -2,15 +2,15 @@ namespace :gitlab do | ||
2 | desc "GITLAB | Run all tests" | 2 | desc "GITLAB | Run all tests" |
3 | task :test do | 3 | task :test do |
4 | cmds = [ | 4 | cmds = [ |
5 | - "rake db:setup", | ||
6 | - "rake db:seed_fu", | ||
7 | - "rake spinach", | ||
8 | - "rake spec", | ||
9 | - "rake jasmine:ci" | 5 | + %W(rake db:setup), |
6 | + %W(rake db:seed_fu), | ||
7 | + %W(rake spinach), | ||
8 | + %W(rake spec), | ||
9 | + %W(rake jasmine:ci) | ||
10 | ] | 10 | ] |
11 | 11 | ||
12 | cmds.each do |cmd| | 12 | cmds.each do |cmd| |
13 | - system(cmd + " RAILS_ENV=test") | 13 | + system({'RAILS_ENV' => 'test'}, *cmd) |
14 | 14 | ||
15 | raise "#{cmd} failed!" unless $?.exitstatus.zero? | 15 | raise "#{cmd} failed!" unless $?.exitstatus.zero? |
16 | end | 16 | end |
lib/tasks/sidekiq.rake
1 | namespace :sidekiq do | 1 | namespace :sidekiq do |
2 | desc "GITLAB | Stop sidekiq" | 2 | desc "GITLAB | Stop sidekiq" |
3 | task :stop do | 3 | task :stop do |
4 | - system "script/background_jobs stop" | 4 | + system *%W(script/background_jobs stop) |
5 | end | 5 | end |
6 | 6 | ||
7 | desc "GITLAB | Start sidekiq" | 7 | desc "GITLAB | Start sidekiq" |
8 | task :start do | 8 | task :start do |
9 | - system "script/background_jobs start" | 9 | + system *%W(script/background_jobs start) |
10 | end | 10 | end |
11 | 11 | ||
12 | desc 'GitLab | Restart sidekiq' | 12 | desc 'GitLab | Restart sidekiq' |
13 | task :restart do | 13 | task :restart do |
14 | - system "script/background_jobs restart" | 14 | + system *%W(script/background_jobs restart) |
15 | end | 15 | end |
16 | 16 | ||
17 | desc "GITLAB | Start sidekiq with launchd on Mac OS X" | 17 | desc "GITLAB | Start sidekiq with launchd on Mac OS X" |
18 | task :launchd do | 18 | task :launchd do |
19 | - system "script/background_jobs start_no_deamonize" | 19 | + system *%W(script/background_jobs start_no_deamonize) |
20 | end | 20 | end |
21 | end | 21 | end |
spec/models/gollum_wiki_spec.rb
@@ -2,12 +2,6 @@ require "spec_helper" | @@ -2,12 +2,6 @@ require "spec_helper" | ||
2 | 2 | ||
3 | describe GollumWiki do | 3 | describe GollumWiki do |
4 | 4 | ||
5 | - def create_temp_repo(path) | ||
6 | - FileUtils.mkdir_p path | ||
7 | - command = "git init --quiet #{path};" | ||
8 | - system(command) | ||
9 | - end | ||
10 | - | ||
11 | def remove_temp_repo(path) | 5 | def remove_temp_repo(path) |
12 | FileUtils.rm_rf path | 6 | FileUtils.rm_rf path |
13 | end | 7 | end |
spec/models/wiki_page_spec.rb
@@ -2,12 +2,6 @@ require "spec_helper" | @@ -2,12 +2,6 @@ require "spec_helper" | ||
2 | 2 | ||
3 | describe WikiPage do | 3 | describe WikiPage do |
4 | 4 | ||
5 | - def create_temp_repo(path) | ||
6 | - FileUtils.mkdir_p path | ||
7 | - command = "git init --quiet #{path};" | ||
8 | - system(command) | ||
9 | - end | ||
10 | - | ||
11 | def remove_temp_repo(path) | 5 | def remove_temp_repo(path) |
12 | FileUtils.rm_rf path | 6 | FileUtils.rm_rf path |
13 | end | 7 | end |
spec/support/test_env.rb
@@ -104,10 +104,12 @@ module TestEnv | @@ -104,10 +104,12 @@ module TestEnv | ||
104 | 104 | ||
105 | def reset_satellite_dir | 105 | def reset_satellite_dir |
106 | setup_stubs | 106 | setup_stubs |
107 | - FileUtils.cd(seed_satellite_path) do | ||
108 | - `git reset --hard --quiet` | ||
109 | - `git clean -fx` | ||
110 | - `git checkout --quiet origin/master` | 107 | + [ |
108 | + %W(git reset --hard --quiet), | ||
109 | + %W(git clean -fx), | ||
110 | + %W(git checkout --quiet origin/master) | ||
111 | + ].each do |git_cmd| | ||
112 | + system(*git_cmd, chdir: seed_satellite_path) | ||
111 | end | 113 | end |
112 | end | 114 | end |
113 | 115 | ||
@@ -117,7 +119,7 @@ module TestEnv | @@ -117,7 +119,7 @@ module TestEnv | ||
117 | repo = repo(namespace, name) | 119 | repo = repo(namespace, name) |
118 | 120 | ||
119 | # Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq | 121 | # Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq |
120 | - system("ln -s -f #{seed_repo_path()} #{repo}") | 122 | + FileUtils.ln_sf(seed_repo_path, repo) |
121 | create_satellite(repo, namespace, name) | 123 | create_satellite(repo, namespace, name) |
122 | end | 124 | end |
123 | 125 | ||
@@ -181,12 +183,11 @@ module TestEnv | @@ -181,12 +183,11 @@ module TestEnv | ||
181 | # Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already | 183 | # Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already |
182 | satellite_dir = File.dirname(satellite_repo) | 184 | satellite_dir = File.dirname(satellite_repo) |
183 | FileUtils.mkdir_p(satellite_dir) unless File.exists?(satellite_dir) | 185 | FileUtils.mkdir_p(satellite_dir) unless File.exists?(satellite_dir) |
184 | - system("ln -s -f #{seed_satellite_path} #{satellite_repo}") | 186 | + FileUtils.ln_sf(seed_satellite_path, satellite_repo) |
185 | end | 187 | end |
186 | 188 | ||
187 | def create_temp_repo(path) | 189 | def create_temp_repo(path) |
188 | FileUtils.mkdir_p path | 190 | FileUtils.mkdir_p path |
189 | - command = "git init --quiet --bare #{path};" | ||
190 | - system(command) | 191 | + system(*%W(git init --quiet --bare -- #{path})) |
191 | end | 192 | end |
192 | end | 193 | end |