From d3addc60556ff9098b83e5e7174dbd5f87c2112f Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 15 Jul 2014 18:19:29 +0200 Subject: [PATCH] Make services wait for a filesystem to be mounted --- CHANGELOG | 1 + README.md | 11 +++++++++++ files/gitlab-cookbooks/gitlab/attributes/default.rb | 5 +++++ files/gitlab-cookbooks/gitlab/libraries/gitlab.rb | 2 ++ files/gitlab-cookbooks/gitlab/templates/default/mount_point_check.erb | 6 ++++++ files/gitlab-cookbooks/gitlab/templates/default/sv-nginx-run.erb | 2 +- files/gitlab-cookbooks/gitlab/templates/default/sv-postgresql-run.erb | 2 +- files/gitlab-cookbooks/gitlab/templates/default/sv-redis-run.erb | 1 + files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb | 1 + files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb | 1 + files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-run.erb | 1 + 11 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 files/gitlab-cookbooks/gitlab/templates/default/mount_point_check.erb diff --git a/CHANGELOG b/CHANGELOG index c29c1d9..f65c228 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ omnibus-gitlab repository. - Support external Redis instances (sponsored by O'Reilly Media) - Only reject SMTP attributes which are nil - Support changing the 'restricted_visibility_levels' option (Javier Palomo) +- Only start omnibus-gitlab services after a given filesystem is mounted 7.0.0-ee.omnibus.1 - Fix MySQL build for Ubuntu 14.04 diff --git a/README.md b/README.md index bc358a1..c853ade 100644 --- a/README.md +++ b/README.md @@ -569,6 +569,17 @@ gitlab_rails['redis_host'] = redis.example.com gitlab_rails['redis_port'] = 6380 # defaults to 6379 ``` +## Only start omnibus-gitlab services after a given filesystem is mounted + +If you want to prevent omnibus-gitlab services (nginx, redis, unicorn etc.) +from starting before a given filesystem is mounted, add the following to +`/etc/gitlab/gitlab.rb`: + +```ruby +# wait for /var/opt/gitlab to be mounted +high_availability['mountpoint'] = '/var/opt/gitlab' +``` + ## Building your own package See [the separate build documentation](doc/build.md). diff --git a/files/gitlab-cookbooks/gitlab/attributes/default.rb b/files/gitlab-cookbooks/gitlab/attributes/default.rb index 6c36a65..ed385ec 100644 --- a/files/gitlab-cookbooks/gitlab/attributes/default.rb +++ b/files/gitlab-cookbooks/gitlab/attributes/default.rb @@ -276,3 +276,8 @@ default['gitlab']['remote-syslog']['log_directory'] = "/var/log/gitlab/remote-sy default['gitlab']['remote-syslog']['destination_host'] = "localhost" default['gitlab']['remote-syslog']['destination_port'] = 514 default['gitlab']['remote-syslog']['services'] = %w{redis nginx unicorn gitlab-rails postgresql sidekiq} + +### +# High Availability +### +default['gitlab']['high-availability']['mountpoint'] = nil diff --git a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb index 9887d57..a48ee80 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/gitlab.rb @@ -45,6 +45,7 @@ module Gitlab nginx Mash.new logging Mash.new remote_syslog Mash.new + high_availability node nil external_url nil git_data_dir nil @@ -159,6 +160,7 @@ module Gitlab "nginx", "logging", "remote_syslog", + "high_availability", "postgresql" ].each do |key| rkey = key.gsub('_', '-') diff --git a/files/gitlab-cookbooks/gitlab/templates/default/mount_point_check.erb b/files/gitlab-cookbooks/gitlab/templates/default/mount_point_check.erb new file mode 100644 index 0000000..8b467a1 --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/mount_point_check.erb @@ -0,0 +1,6 @@ +<% if node['gitlab']['high-availability']['mountpoint'] %> +if ! mountpoint -q '<%= node['gitlab']['high-availability']['mountpoint'] %>' ; then + echo 'Refusing to start because <%= node['gitlab']['high-availability']['mountpoint'] %> is not a mountpoint.' + exit 1 +fi +<% end %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-nginx-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-nginx-run.erb index e3af575..0efbbc7 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/sv-nginx-run.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-nginx-run.erb @@ -1,4 +1,4 @@ #!/bin/sh exec 2>&1 +<%= render("mount_point_check.erb") %> exec chpst -P /opt/gitlab/embedded/sbin/nginx -c <%= File.join(node['gitlab']['nginx']['dir'], "etc", "nginx.conf") %> - diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-postgresql-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-postgresql-run.erb index 34dd33b..0d54f45 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/sv-postgresql-run.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-postgresql-run.erb @@ -1,4 +1,4 @@ #!/bin/sh exec 2>&1 +<%= render("mount_point_check.erb") %> exec chpst -P -U <%= node['gitlab']['postgresql']['username'] %> -u <%= node['gitlab']['postgresql']['username'] %> /opt/gitlab/embedded/bin/postgres -D <%= File.join(node['gitlab']['postgresql']['dir'], "data") %> - diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-redis-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-redis-run.erb index b20e70e..f96f4de 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/sv-redis-run.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-redis-run.erb @@ -1,3 +1,4 @@ #!/bin/sh exec 2>&1 +<%= render("mount_point_check.erb") %> exec chpst -P -U <%= node['gitlab']['redis']['username'] %> -u <%= node['gitlab']['redis']['username'] %> /opt/gitlab/embedded/bin/redis-server <%= File.join(node['gitlab']['redis']['dir'], "redis.conf") %> diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb index fe0f013..b02ad69 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-remote-syslog-run.erb @@ -1,3 +1,4 @@ #!/bin/sh exec 2>&1 +<%= render("mount_point_check.erb") %> exec /opt/gitlab/embedded/bin/remote_syslog --no-detach --debug-level DEBUG -c <%= node['gitlab']['remote-syslog']['dir'] %>/remote_syslog.yml diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb index 5a049bf..0a890c3 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-sidekiq-run.erb @@ -3,4 +3,5 @@ cd <%= node['gitlab']['gitlab-rails']['dir'] %>/working exec 2>&1 +<%= render("mount_point_check.erb") %> exec chpst -P -U <%= node['gitlab']['user']['username'] %> -u <%= node['gitlab']['user']['username'] %> /usr/bin/env BUNDLE_GEMFILE=/opt/gitlab/embedded/service/gitlab-rails/Gemfile HOME="<%= node['gitlab']['user']['home'] %>" /opt/gitlab/embedded/bin/bundle exec sidekiq -q post_receive -q mailer -q system_hook -q project_web_hook -q gitlab_shell -q common -q default -e <%= node['gitlab']['gitlab-rails']['environment'] %> -r /opt/gitlab/embedded/service/gitlab-rails diff --git a/files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-run.erb b/files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-run.erb index 32967d6..f6237a2 100644 --- a/files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-run.erb +++ b/files/gitlab-cookbooks/gitlab/templates/default/sv-unicorn-run.erb @@ -64,6 +64,7 @@ function is_unicorn function start_unicorn_master { + <%= render("mount_point_check.erb") %> chpst -P -U <%= node['gitlab']['user']['username'] %> -u <%= node['gitlab']['user']['username'] %> /usr/bin/env HOME="<%= node['gitlab']['user']['home'] %>" /opt/gitlab/embedded/bin/bundle exec unicorn -D -E <%= node['gitlab']['gitlab-rails']['environment'] %> -c <%= File.join(node['gitlab']['gitlab-rails']['dir'], "etc", "unicorn.rb") %> /opt/gitlab/embedded/service/gitlab-rails/config.ru } -- libgit2 0.21.2