Commit c20ae1424a64985bf4ede2dd9637776f85a03f7d

Authored by Jacob Vosmaer
2 parents 9018a7e2 60405481

Merge branch 'guard_migrations' into 'master'

Guard migrations
files/gitlab-cookbooks/gitlab/libraries/helper.rb
@@ -76,12 +76,22 @@ class OmnibusHelper @@ -76,12 +76,22 @@ class OmnibusHelper
76 File.symlink?("/opt/gitlab/service/#{service_name}") && service_up?(service_name) 76 File.symlink?("/opt/gitlab/service/#{service_name}") && service_up?(service_name)
77 end 77 end
78 78
  79 + def self.not_listening?(service_name)
  80 + File.exists?("/opt/gitlab/service/#{service_name}/down") && service_down?(service_name)
  81 + end
  82 +
79 def self.service_up?(service_name) 83 def self.service_up?(service_name)
80 o = Mixlib::ShellOut.new("/opt/gitlab/bin/gitlab-ctl status #{service_name}") 84 o = Mixlib::ShellOut.new("/opt/gitlab/bin/gitlab-ctl status #{service_name}")
81 o.run_command 85 o.run_command
82 o.exitstatus == 0 86 o.exitstatus == 0
83 end 87 end
84 88
  89 + def self.service_down?(service_name)
  90 + o = Mixlib::ShellOut.new("/opt/gitlab/bin/gitlab-ctl status #{service_name}")
  91 + o.run_command
  92 + o.exitstatus == 3
  93 + end
  94 +
85 end 95 end
86 96
87 module SingleQuoteHelper 97 module SingleQuoteHelper
files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb
@@ -44,6 +44,9 @@ dependent_services = [] @@ -44,6 +44,9 @@ dependent_services = []
44 dependent_services << "service[unicorn]" if OmnibusHelper.should_notify?("unicorn") 44 dependent_services << "service[unicorn]" if OmnibusHelper.should_notify?("unicorn")
45 dependent_services << "service[sidekiq]" if OmnibusHelper.should_notify?("sidekiq") 45 dependent_services << "service[sidekiq]" if OmnibusHelper.should_notify?("sidekiq")
46 46
  47 +redis_not_listening = OmnibusHelper.not_listening("redis")
  48 +postgresql_not_listening = OmnibusHelper.not_listening("postgresql")
  49 +
47 template_symlink File.join(gitlab_rails_etc_dir, "secret") do 50 template_symlink File.join(gitlab_rails_etc_dir, "secret") do
48 link_from File.join(gitlab_rails_source_dir, ".secret") 51 link_from File.join(gitlab_rails_source_dir, ".secret")
49 source "secret_token.erb" 52 source "secret_token.erb"
@@ -92,7 +95,9 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;gitlab.yml&quot;) do @@ -92,7 +95,9 @@ template_symlink File.join(gitlab_rails_etc_dir, &quot;gitlab.yml&quot;) do
92 mode "0644" 95 mode "0644"
93 variables(node['gitlab']['gitlab-rails'].to_hash) 96 variables(node['gitlab']['gitlab-rails'].to_hash)
94 restarts dependent_services 97 restarts dependent_services
95 - notifies :run, 'execute[clear the gitlab-rails cache]' 98 + unless redis_not_listening
  99 + notifies :run, 'execute[clear the gitlab-rails cache]'
  100 + end
96 end 101 end
97 102
98 template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do 103 template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do
@@ -131,8 +136,8 @@ end @@ -131,8 +136,8 @@ end
131 # Only run `rake db:migrate` when the gitlab-rails version has changed 136 # Only run `rake db:migrate` when the gitlab-rails version has changed
132 remote_file File.join(gitlab_rails_dir, 'VERSION') do 137 remote_file File.join(gitlab_rails_dir, 'VERSION') do
133 source "file:///opt/gitlab/embedded/service/gitlab-rails/VERSION" 138 source "file:///opt/gitlab/embedded/service/gitlab-rails/VERSION"
134 - notifies :run, 'execute[migrate database]'  
135 - notifies :run, 'execute[clear the gitlab-rails cache]' 139 + notifies :run, 'execute[migrate database]' unless postgresql_not_listening
  140 + notifies :run, 'execute[clear the gitlab-rails cache]' unless redis_not_listening
136 end 141 end
137 142
138 execute "chown -R #{node['gitlab']['user']['username']} /opt/gitlab/embedded/service/gitlab-rails/public" 143 execute "chown -R #{node['gitlab']['user']['username']} /opt/gitlab/embedded/service/gitlab-rails/public"