diff --git a/files/gitlab-cookbooks/gitlab/libraries/helper.rb b/files/gitlab-cookbooks/gitlab/libraries/helper.rb index a2eefe1..254652e 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/helper.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/helper.rb @@ -76,12 +76,22 @@ class OmnibusHelper File.symlink?("/opt/gitlab/service/#{service_name}") && service_up?(service_name) end + def self.not_listening?(service_name) + File.exists?("/opt/gitlab/service/#{service_name}/down") && service_down?(service_name) + end + def self.service_up?(service_name) o = Mixlib::ShellOut.new("/opt/gitlab/bin/gitlab-ctl status #{service_name}") o.run_command o.exitstatus == 0 end + def self.service_down?(service_name) + o = Mixlib::ShellOut.new("/opt/gitlab/bin/gitlab-ctl status #{service_name}") + o.run_command + o.exitstatus == 3 + end + end module SingleQuoteHelper diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb index 66fa5c3..7f1bd46 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb @@ -44,6 +44,9 @@ dependent_services = [] dependent_services << "service[unicorn]" if OmnibusHelper.should_notify?("unicorn") dependent_services << "service[sidekiq]" if OmnibusHelper.should_notify?("sidekiq") +redis_not_listening = OmnibusHelper.not_listening("redis") +postgresql_not_listening = OmnibusHelper.not_listening("postgresql") + template_symlink File.join(gitlab_rails_etc_dir, "secret") do link_from File.join(gitlab_rails_source_dir, ".secret") source "secret_token.erb" @@ -92,7 +95,9 @@ template_symlink File.join(gitlab_rails_etc_dir, "gitlab.yml") do mode "0644" variables(node['gitlab']['gitlab-rails'].to_hash) restarts dependent_services - notifies :run, 'execute[clear the gitlab-rails cache]' + unless redis_not_listening + notifies :run, 'execute[clear the gitlab-rails cache]' + end end template_symlink File.join(gitlab_rails_etc_dir, "rack_attack.rb") do @@ -131,8 +136,8 @@ end # Only run `rake db:migrate` when the gitlab-rails version has changed remote_file File.join(gitlab_rails_dir, 'VERSION') do source "file:///opt/gitlab/embedded/service/gitlab-rails/VERSION" - notifies :run, 'execute[migrate database]' - notifies :run, 'execute[clear the gitlab-rails cache]' + notifies :run, 'execute[migrate database]' unless postgresql_not_listening + notifies :run, 'execute[clear the gitlab-rails cache]' unless redis_not_listening end execute "chown -R #{node['gitlab']['user']['username']} /opt/gitlab/embedded/service/gitlab-rails/public" -- libgit2 0.21.2