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 | 1 | class Admin::BackgroundJobsController < Admin::ApplicationController |
2 | 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 | 5 | end |
5 | 6 | end | ... | ... |
config/initializers/2_app.rb
lib/backup/manager.rb
... | ... | @@ -8,7 +8,7 @@ module Backup |
8 | 8 | s[:db_version] = "#{ActiveRecord::Migrator.current_version}" |
9 | 9 | s[:backup_created_at] = Time.now |
10 | 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 | 13 | Dir.chdir(Gitlab.config.backup.path) |
14 | 14 | |
... | ... | @@ -98,5 +98,10 @@ module Backup |
98 | 98 | exit 1 |
99 | 99 | end |
100 | 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 | 106 | end |
102 | 107 | end | ... | ... |
lib/gitlab/logger.rb
... | ... | @@ -11,12 +11,14 @@ module Gitlab |
11 | 11 | def self.read_latest |
12 | 12 | path = Rails.root.join("log", file_name) |
13 | 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 | 16 | end |
16 | 17 | |
17 | 18 | def self.read_latest_for filename |
18 | 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 | 22 | end |
21 | 23 | |
22 | 24 | def self.build | ... | ... |
lib/gitlab/upgrader.rb
... | ... | @@ -42,28 +42,33 @@ module Gitlab |
42 | 42 | end |
43 | 43 | |
44 | 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 | 48 | last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s |
48 | 49 | end |
49 | 50 | |
50 | 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 | 61 | end |
61 | 62 | |
63 | + def env | |
64 | + {'RAILS_ENV' => 'production'} | |
65 | + end | |
66 | + | |
62 | 67 | def upgrade |
63 | 68 | update_commands.each do |title, cmd| |
64 | 69 | puts title |
65 | - puts " -> #{cmd}" | |
66 | - if system(cmd) | |
70 | + puts " -> #{cmd.join(' ')}" | |
71 | + if system(env, *cmd) | |
67 | 72 | puts " -> OK" |
68 | 73 | else |
69 | 74 | puts " -> FAILED" | ... | ... |
lib/tasks/gitlab/check.rake
... | ... | @@ -168,7 +168,7 @@ namespace :gitlab do |
168 | 168 | def check_migrations_are_up |
169 | 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 | 173 | unless migration_status =~ /down\s+\d{14}/ |
174 | 174 | puts "yes".green |
... | ... | @@ -295,7 +295,7 @@ namespace :gitlab do |
295 | 295 | "user.email" => Gitlab.config.gitlab.email_from |
296 | 296 | } |
297 | 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 | 299 | end |
300 | 300 | |
301 | 301 | if correct_options.all? |
... | ... | @@ -628,7 +628,8 @@ namespace :gitlab do |
628 | 628 | end |
629 | 629 | |
630 | 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 | 633 | end |
633 | 634 | end |
634 | 635 | |
... | ... | @@ -739,7 +740,7 @@ namespace :gitlab do |
739 | 740 | |
740 | 741 | def check_git_version |
741 | 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 | 745 | puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\"" |
745 | 746 | print "Git version >= #{required_version} ? ... " | ... | ... |
lib/tasks/gitlab/generate_docs.rake
lib/tasks/gitlab/info.rake
... | ... | @@ -4,20 +4,20 @@ namespace :gitlab do |
4 | 4 | task info: :environment do |
5 | 5 | |
6 | 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 | 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 | 10 | # check Gem version |
11 | - gem_version = run("gem --version") | |
11 | + gem_version = run(%W(gem --version)) | |
12 | 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 | 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 | 17 | puts "" |
18 | 18 | puts "System information".yellow |
19 | 19 | puts "System:\t\t#{os_name || "unknown".red}" |
20 | - puts "Current User:\t#{`whoami`}" | |
20 | + puts "Current User:\t#{run(%W(whoami))}" | |
21 | 21 | puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" |
22 | 22 | puts "RVM Version:\t#{rvm_version}" if rvm_version.present? |
23 | 23 | puts "Ruby Version:\t#{ruby_version || "unknown".red}" | ... | ... |
lib/tasks/gitlab/task_helpers.rake
... | ... | @@ -28,7 +28,7 @@ namespace :gitlab do |
28 | 28 | # It will primarily use lsb_relase to determine the OS. |
29 | 29 | # It has fallbacks to Debian, SuSE, OS X and systems running systemd. |
30 | 30 | def os_name |
31 | - os_name = run("lsb_release -irs") | |
31 | + os_name = run(%W(lsb_release -irs)) | |
32 | 32 | os_name ||= if File.readable?('/etc/system-release') |
33 | 33 | File.read('/etc/system-release') |
34 | 34 | end |
... | ... | @@ -39,7 +39,7 @@ namespace :gitlab do |
39 | 39 | os_name ||= if File.readable?('/etc/SuSE-release') |
40 | 40 | File.read('/etc/SuSE-release') |
41 | 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 | 43 | "Mac OS X #{os_x_version}" |
44 | 44 | end |
45 | 45 | os_name ||= if File.readable?('/etc/os-release') |
... | ... | @@ -80,13 +80,12 @@ namespace :gitlab do |
80 | 80 | # |
81 | 81 | # see also #run_and_match |
82 | 82 | def run(command) |
83 | - unless `#{command} 2>/dev/null`.blank? | |
84 | - `#{command}` | |
85 | - end | |
83 | + output, _ = Gitlab::Popen.popen(command) | |
84 | + output | |
86 | 85 | end |
87 | 86 | |
88 | 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 | 89 | end |
91 | 90 | |
92 | 91 | def gid_for(group_name) |
... | ... | @@ -100,7 +99,7 @@ namespace :gitlab do |
100 | 99 | def warn_user_is_not_gitlab |
101 | 100 | unless @warned_user_not_gitlab |
102 | 101 | gitlab_user = Gitlab.config.gitlab.user |
103 | - current_user = run("whoami").chomp | |
102 | + current_user = run(%W(whoami)).chomp | |
104 | 103 | unless current_user == gitlab_user |
105 | 104 | puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" |
106 | 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 | 2 | desc "GITLAB | Run all tests" |
3 | 3 | task :test do |
4 | 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 | 12 | cmds.each do |cmd| |
13 | - system(cmd + " RAILS_ENV=test") | |
13 | + system({'RAILS_ENV' => 'test'}, *cmd) | |
14 | 14 | |
15 | 15 | raise "#{cmd} failed!" unless $?.exitstatus.zero? |
16 | 16 | end | ... | ... |
lib/tasks/sidekiq.rake
1 | 1 | namespace :sidekiq do |
2 | 2 | desc "GITLAB | Stop sidekiq" |
3 | 3 | task :stop do |
4 | - system "script/background_jobs stop" | |
4 | + system *%W(script/background_jobs stop) | |
5 | 5 | end |
6 | 6 | |
7 | 7 | desc "GITLAB | Start sidekiq" |
8 | 8 | task :start do |
9 | - system "script/background_jobs start" | |
9 | + system *%W(script/background_jobs start) | |
10 | 10 | end |
11 | 11 | |
12 | 12 | desc 'GitLab | Restart sidekiq' |
13 | 13 | task :restart do |
14 | - system "script/background_jobs restart" | |
14 | + system *%W(script/background_jobs restart) | |
15 | 15 | end |
16 | 16 | |
17 | 17 | desc "GITLAB | Start sidekiq with launchd on Mac OS X" |
18 | 18 | task :launchd do |
19 | - system "script/background_jobs start_no_deamonize" | |
19 | + system *%W(script/background_jobs start_no_deamonize) | |
20 | 20 | end |
21 | 21 | end | ... | ... |
spec/models/gollum_wiki_spec.rb
spec/models/wiki_page_spec.rb
spec/support/test_env.rb
... | ... | @@ -104,10 +104,12 @@ module TestEnv |
104 | 104 | |
105 | 105 | def reset_satellite_dir |
106 | 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 | 113 | end |
112 | 114 | end |
113 | 115 | |
... | ... | @@ -117,7 +119,7 @@ module TestEnv |
117 | 119 | repo = repo(namespace, name) |
118 | 120 | |
119 | 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 | 123 | create_satellite(repo, namespace, name) |
122 | 124 | end |
123 | 125 | |
... | ... | @@ -181,12 +183,11 @@ module TestEnv |
181 | 183 | # Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already |
182 | 184 | satellite_dir = File.dirname(satellite_repo) |
183 | 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 | 187 | end |
186 | 188 | |
187 | 189 | def create_temp_repo(path) |
188 | 190 | FileUtils.mkdir_p path |
189 | - command = "git init --quiet --bare #{path};" | |
190 | - system(command) | |
191 | + system(*%W(git init --quiet --bare -- #{path})) | |
191 | 192 | end |
192 | 193 | end | ... | ... |