# HG changeset patch
# User Clemens Beck <cbeck@gitlab.com>
# Date 1698266905 0
#      Wed Oct 25 20:48:25 2023 +0000
# Node ID 5f959b9132f5c68dc2e4fdadbe35afad8146c34e
# Parent  e09afc31f635b5e879b5130558ce5955a9003346
Restart NGINX on version change

Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/4837

Changelog: fixed

diff --git a/files/gitlab-cookbooks/nginx/recipes/enable.rb b/files/gitlab-cookbooks/nginx/recipes/enable.rb
--- a/files/gitlab-cookbooks/nginx/recipes/enable.rb
+++ b/files/gitlab-cookbooks/nginx/recipes/enable.rb
@@ -26,6 +26,12 @@
   log_options logging_settings[:options]
 end
 
+version_file 'Create version file for NGINX' do
+  version_file_path File.join(node['gitlab']['nginx']['dir'], 'VERSION')
+  version_check_cmd '/opt/gitlab/embedded/sbin/nginx -ver 2>&1'
+  notifies :restart, 'runit_service[nginx]'
+end
+
 execute 'reload nginx' do
   command 'gitlab-ctl hup nginx'
   action :nothing
diff --git a/spec/chef/cookbooks/gitlab/recipes/nginx_spec.rb b/spec/chef/cookbooks/gitlab/recipes/nginx_spec.rb
--- a/spec/chef/cookbooks/gitlab/recipes/nginx_spec.rb
+++ b/spec/chef/cookbooks/gitlab/recipes/nginx_spec.rb
@@ -505,6 +505,15 @@
       expect(chef_run).to render_file(gitlab_http_config).with_content('return 301 https://fauxhai.local:80$request_uri;')
     end
 
+    it 'creates a default VERSION file and restarts service' do
+      expect(chef_run).to create_version_file('Create version file for NGINX').with(
+        version_file_path: '/var/opt/gitlab/nginx/VERSION',
+        version_check_cmd: '/opt/gitlab/embedded/sbin/nginx -ver 2>&1'
+      )
+
+      expect(chef_run.version_file('Create version file for NGINX')).to notify('runit_service[nginx]').to(:restart)
+    end
+
     context 'when smartcard authentication is enabled' do
       let(:gitlab_smartcard_http_config) { '/var/opt/gitlab/nginx/conf/gitlab-smartcard-http.conf' }