Skip to content
Snippets Groups Projects
Commit 9fdb78d2 authored by Stan Hu's avatar Stan Hu
Browse files

Restart PG automatically on version change

parent cb7d5c92
No related branches found
No related tags found
1 merge request!72Intermediate build for testing purposes
......@@ -1254,6 +1254,10 @@
# Set this if you have disabled the bundled PostgreSQL but still want to use the backup rake tasks
# postgresql['version'] = 10
##! Automatically restart PostgreSQL service when version changes.
# postgresql['auto_restart_on_version_change'] = true
################################################################################
## GitLab Redis
##! **Can be disabled if you are using your own Redis instance.**
......
......@@ -117,3 +117,6 @@
# Listen Check settings
default['postgresql']['max_service_checks'] = 20
default['postgresql']['service_check_interval'] = 5
# Automatically restart on version changes
default['postgresql']['auto_restart_on_version_change'] = true
account_helper = AccountHelper.new(node)
pg_helper = PgHelper.new(node)
omnibus_helper = OmnibusHelper.new(node)
postgresql_username = account_helper.postgresql_user
postgresql_group = account_helper.postgresql_group
......@@ -31,6 +32,12 @@
not_if { pg_helper.replica? }
end
version_file 'Create version file for PostgreSQL' do
version_file_path File.join(node['postgresql']['dir'], 'VERSION')
version_check_cmd "/opt/gitlab/embedded/bin/postgres --version"
notifies :restart, 'runit_service[postgresql]', :immediately if node['postgresql']['auto_restart_on_version_change'] && pg_helper.is_running? && omnibus_helper.should_notify?("postgresql") && pg_helper.bootstrapped?
end
ruby_block 'warn pending postgresql restart' do
block do
message = <<~MESSAGE
......@@ -42,6 +49,7 @@
LoggingHelper.warning(message)
end
only_if { pg_helper.is_running? && pg_helper.running_version != pg_helper.version }
not_if { node['postgresql']['auto_restart_on_version_change'] }
end
execute 'reload postgresql' do
......
......@@ -675,7 +675,8 @@
context 'when running version and installed version differ' do
before do
allow(Gitlab).to receive(:[]).and_call_original
allow_any_instance_of(PgHelper).to receive(:version).and_return(PGVersion.new('expectation'))
allow_any_instance_of(PgHelper).to receive(:running_version).and_return(PGVersion.new('reality'))
end
......@@ -678,9 +679,10 @@
allow_any_instance_of(PgHelper).to receive(:version).and_return(PGVersion.new('expectation'))
allow_any_instance_of(PgHelper).to receive(:running_version).and_return(PGVersion.new('reality'))
end
it 'warns the user that a restart is needed' do
allow_any_instance_of(PgHelper).to receive(:is_running?).and_return(true)
expect(chef_run).to run_ruby_block('warn pending postgresql restart')
context 'by defaul' do
it 'does not warns the user that a restart is needed' do
expect(chef_run).not_to run_ruby_block('warn pending postgresql restart')
end
end
......@@ -685,7 +687,22 @@
end
it 'does not warns the user that a restart is needed when postgres is stopped' do
expect(chef_run).not_to run_ruby_block('warn pending postgresql restart')
context 'when auto_restart_on_version_change is set to false' do
before do
stub_gitlab_rb(
postgresql: {
auto_restart_on_version_change: false
}
)
end
it 'warns the user that a restart is needed' do
allow_any_instance_of(PgHelper).to receive(:is_running?).and_return(true)
expect(chef_run).to run_ruby_block('warn pending postgresql restart')
end
it 'does not warns the user that a restart is needed when postgres is stopped' do
expect(chef_run).not_to run_ruby_block('warn pending postgresql restart')
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment