Просмотр исходного кода

Maintenance: Automatic process shutdown after certain configuration changes

Zammad will now cause a self-shutdown of all running processes after certain configuration changes by default. It is the responsibility of the controlling process manager (e.g. Docker,
Kubernetes, systemd) to bring them up again by way of a proper restart policy. This is the default for vanilla Docker, Kubernetes or Package deployments of Zammad.

The previous environment variable APP_RESTART_CMD is not supported any more.

For systems where this behaviour is not wanted, it can be disabled by setting the Zammad Setting `auto_shutdown` to `false`.

Co-authored-by: Mantas Masalskis <mm@zammad.com>
Co-authored-by: Martin Gruner <mg@zammad.com>
Martin Gruner 2 месяцев назад
Родитель
Сommit
0e24872409

+ 0 - 1
.dev/rubocop/todo.rspec.yml

@@ -269,7 +269,6 @@ RSpec/MessageSpies:
     - 'spec/db/migrate/issue_1660_fix_tree_select_configurations_spec.rb'
     - 'spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb'
     - 'spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb'
-    - 'spec/jobs/app_version_restart_job_spec.rb'
     - 'spec/jobs/search_index_job_spec.rb'
     - 'spec/lib/import/base_factory_examples.rb'
     - 'spec/lib/import/helper_spec.rb'

+ 0 - 1
.gitlab/ci/browser/__templates__.yml

@@ -5,7 +5,6 @@
     - .tags_docker_low_concurrency
   variables:
     RAILS_ENV: "production"
-    APP_RESTART_CMD: 'bundle exec rake environment zammad:ci:app:restart'
   script:
     - |
       script/build/test_slice_tests.sh $TEST_SLICE

+ 1 - 3
app/assets/javascripts/app/controllers/_plugin/maintenance.coffee

@@ -72,7 +72,7 @@ class Maintenance extends App.Controller
 
     @messageRestartManual = new App.SessionMessage(
       head:         __('Zammad requires a restart!')
-      message:      __('Some system settings have changed, please restart all Zammad processes! If you want to do this automatically, set environment variable APP_RESTART_CMD="/path/to/your_app_script.sh restart".')
+      message:      __('Some system settings have changed, please restart all Zammad processes!')
       keyboard:     false
       backdrop:     false
       buttonClose:  false
@@ -105,8 +105,6 @@ class Maintenance extends App.Controller
       @appVersion = data.app_version
       return
     @appVersion = data.app_version
-    localAppVersion = @appVersion.split(':')
-    return if localAppVersion[1] isnt 'true'
 
     App.SessionStorage.clear()
 

+ 1 - 6
app/controllers/settings_controller.rb

@@ -26,12 +26,7 @@ class SettingsController < ApplicationController
 
   # PUT /settings/1
   def update
-    clean_params = keep_certain_attributes
-
-    name = Setting.find(params[:id]).name
-    Zammad::Restart.perform if %w[http_type fqdn].include?(name)
-
-    model_update_render(Setting, clean_params)
+    model_update_render(Setting, keep_certain_attributes)
   end
 
   # PUT /settings/image/:id

+ 0 - 9
app/jobs/app_version_restart_job.rb

@@ -1,9 +0,0 @@
-# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
-
-class AppVersionRestartJob < ApplicationJob
-  def perform(cmd)
-    Rails.logger.info "executing CMD: #{cmd}"
-    ::Kernel.system(cmd)
-    Rails.logger.info "executed CMD: #{cmd}"
-  end
-end

+ 2 - 2
app/models/object_manager/attribute.rb

@@ -756,9 +756,9 @@ to send no browser reload event, pass false
     # sent maintenance message to clients
     if send_event
       if execute_db_count.nonzero?
-        Zammad::Restart.perform
+        AppVersion.trigger_restart
       elsif execute_config_count.nonzero?
-        AppVersion.set(true, 'config_changed')
+        AppVersion.trigger_browser_reload AppVersion::MSG_CONFIG_CHANGED
       end
     end
     true

+ 1 - 1
app/models/setting.rb

@@ -224,7 +224,7 @@ reload config settings
   def check_refresh
     return if ['auth_saml_credentials'].exclude?(name)
 
-    AppVersion.set(true, AppVersion::MSG_CONFIG_CHANGED)
+    AppVersion.trigger_browser_reload AppVersion::MSG_CONFIG_CHANGED
   end
 end
 # rubocop:enable Style/ClassVars

+ 3 - 1
config/initializers/zzz_action_cable_preferences.rb

@@ -26,7 +26,9 @@ end
 
 Rails.application.reloader.to_prepare do
   begin
-    request_origins = ['http://localhost:3000']
+    Rails.application.config.action_cable.allow_same_origin_as_host = true
+    # Support for configurations where the HTTP_HOST header is not correctly forwarded:
+    request_origins = [%r{https?://localhost:\d+}]
     request_origins << "#{Setting.get('http_type')}://#{Setting.get('fqdn')}"
     Rails.application.config.action_cable.allowed_request_origins = request_origins
     Rails.application.config.action_cable.disable_request_forgery_protection = true if !Rails.env.production?

+ 4 - 0
config/puma.rb

@@ -11,6 +11,10 @@ environment ENV.fetch('RAILS_ENV', 'development')
 
 preload_app!
 
+on_booted do
+  AppVersion.start_maintenance_thread(process_name: 'puma')
+end
+
 if worker_count.positive?
   on_worker_boot do
     ActiveRecord::Base.establish_connection

+ 19 - 2
contrib/docker/docker-entrypoint.sh

@@ -116,13 +116,30 @@ elif [ "$1" = 'zammad-nginx' ]; then
   check_zammad_ready
 
   # configure nginx
+
+  # Ensure that nginx has a short TTL so that recreated containers with new IP addresses are found.
+  NAMESERVER=$(grep "nameserver" < /etc/resolv.conf | awk '{print $2}')
+  echo "resolver $NAMESERVER valid=5s;" > /etc/nginx/conf.d/resolver.conf
+
+  # Inject docker related settings into the nginx configuration.
+  #
+  # There is a workaround needed to support DNS resolution of upstream container names with short TTL:
+  #   we set the proxy pass directly with a variable including the URL (!), rather than just referring to the
+  #   upstream {} definition. For details, see https://tenzer.dk/nginx-with-dynamic-upstreams/.
   sed -e "s#\(listen\)\(.*\)80#\1\2${NGINX_PORT}#g" \
       -e "s#proxy_set_header X-Forwarded-Proto .*;#proxy_set_header X-Forwarded-Proto ${NGINX_SERVER_SCHEME};#g" \
-      -e "s#server .*:3000#server ${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT}#g" \
-      -e "s#server .*:6042#server ${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT}#g" \
+      -e "s#proxy_pass http://zammad-railsserver;#set \$zammad_railsserver_url http://${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT}; proxy_pass \$zammad_railsserver_url;#g" \
+      -e "s#proxy_pass http://zammad-websocket;#set \$zammad_websocket_url http://${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT}; proxy_pass \$zammad_websocket_url;#g" \
       -e "s#server_name .*#server_name ${NGINX_SERVER_NAME};#g" \
       -e 's#/var/log/nginx/zammad.\(access\|error\).log#/dev/stdout#g' < contrib/nginx/zammad.conf > /etc/nginx/sites-enabled/default
 
+  #
+  # Once we can use an nginx version >= 1.27.3, we can drop the proxy_pass workaround above and
+  #   use the new dedicated syntax for configuring resolver usage on the upstream definitions directly:
+  #
+      #-e "s#server .*:3000#server ${ZAMMAD_RAILSSERVER_HOST}:${ZAMMAD_RAILSSERVER_PORT} resolve#g" \
+      #-e "s#server .*:6042#server ${ZAMMAD_WEBSOCKET_HOST}:${ZAMMAD_WEBSOCKET_PORT} resolve#g" \
+
   echo "starting nginx..."
 
   exec /usr/sbin/nginx -g 'daemon off;'

Некоторые файлы не были показаны из-за большого количества измененных файлов