From ff0febcb8f13455a478c714854dd5d7f20aef030 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 9 Apr 2019 20:06:26 -0400 Subject: [PATCH 01/49] Add nathwill/ruby-dbus-systemd for calling systemd --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index d88ef46ad06..925cbc5d801 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,7 @@ gem "byebug", :require => false gem "color", "~>1.8" gem "config", "~>1.6.0", :require => false gem "dalli", "=2.7.6", :require => false +gem "dbus-systemd", "~>1.1.0", :require => false gem "default_value_for", "~>3.0.3" gem "docker-api", "~>1.33.6", :require => false gem "elif", "=0.1.0", :require => false From 37a54d7e40e2d90ad9dcea347368e07b4f250667 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 9 Apr 2019 20:08:39 -0400 Subject: [PATCH 02/49] Add supports_systemd? to MiqEnvironment --- lib/miq_environment.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/miq_environment.rb b/lib/miq_environment.rb index 3f163add1f3..74a8594bbda 100644 --- a/lib/miq_environment.rb +++ b/lib/miq_environment.rb @@ -2,7 +2,7 @@ module MiqEnvironment class Command - EVM_KNOWN_COMMANDS = %w( memcached memcached-tool service apachectl nohup) + EVM_KNOWN_COMMANDS = %w(apachectl memcached memcached-tool nohup service systemctl) def self.supports_memcached? return @supports_memcached unless @supports_memcached.nil? @@ -14,6 +14,11 @@ def self.supports_apache? @supports_apache = is_appliance? && supports_command?('apachectl') end + def self.supports_systemd? + return @supports_systemd unless @supports_systemd.nil? + @supports_systemd = is_appliance? && supports_command?('systemctl') + end + def self.supports_nohup_and_backgrounding? return @supports_nohup unless @supports_nohup.nil? @supports_nohup = is_appliance? && supports_command?('nohup') From 95f15c1c4d93192fbb8fd23dbe5d88b3e707dc02 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 9 Apr 2019 20:12:55 -0400 Subject: [PATCH 03/49] Also log to journald if using systemd --- Gemfile | 2 ++ lib/vmdb/loggers.rb | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 925cbc5d801..0da56e9f4b4 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ require File.join(Bundler::Plugin.index.load_paths("bundler-inject")[0], "bundle # gem "manageiq-gems-pending", ">0", :require => 'manageiq-gems-pending', :git => "https://github.com/ManageIQ/manageiq-gems-pending.git", :branch => "master" +gem "manageiq-loggers", ">0", :require => false, :git => "https://github.com/ManageIQ/manageiq-loggers", :branch => "master" + # Modified gems for gems-pending. Setting sources here since they are git references gem "handsoap", "~>0.2.5", :require => false, :git => "https://github.com/ManageIQ/handsoap.git", :tag => "v0.2.5-5" diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index e41c9464ecb..d4f430d75bb 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -1,4 +1,6 @@ require 'manageiq' +require 'manageiq-loggers' +require 'miq_environment' require 'util/vmdb-logger' module Vmdb @@ -19,6 +21,7 @@ def self.init def self.apply_config(config) apply_config_value(config, $log, :level) + apply_config_value(config, $journald_log, :level) apply_config_value(config, $rails_log, :level_rails) apply_config_value(config, $ansible_tower_log, :level_ansible_tower) apply_config_value(config, $api_log, :level_api) @@ -45,6 +48,7 @@ def self.create_loggers $audit_log = AuditLogger.new(path_dir.join("audit.log")) $container_log = ContainerLogger.new + $journald_log = ManageIQ::Loggers::Journald.new $log = create_multicast_logger(path_dir.join("evm.log")) $rails_log = create_multicast_logger(path_dir.join("#{Rails.env}.log")) $api_log = create_multicast_logger(path_dir.join("api.log")) @@ -73,6 +77,7 @@ def self.create_loggers def self.create_multicast_logger(log_file_path, logger_class = VMDBLogger) logger_class.new(log_file_path).tap do |logger| logger.extend(ActiveSupport::Logger.broadcast($container_log)) if ENV["CONTAINER"] + logger.extend(ActiveSupport::Logger.broadcast($journald_log)) if MiqEnvironment::Command.supports_systemd? end end private_class_method :create_multicast_logger From 4650543501410c3f34b5ee4a5791331d0c2cb9a9 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 9 Apr 2019 20:17:09 -0400 Subject: [PATCH 04/49] Add supports_container? and systemd_worker? --- app/models/miq_worker.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 2863717472e..ae02f86ff74 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -358,6 +358,20 @@ def containerized_worker? self.class.containerized_worker? end + def self.supports_systemd? + # Override this in a sub-class that supports being run as + # a systemd unit + false + end + + def self.systemd_worker? + MiqEnvironment::Command.supports_systemd? && supports_systemd? + end + + def systemd_worker? + self.class.systemd_worker? + end + def start_runner if ENV['MIQ_SPAWN_WORKERS'] || !Process.respond_to?(:fork) start_runner_via_spawn From 0d4bc6609f92f268b363c2e2e35524dc76d65841 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 9 Apr 2019 21:04:00 -0400 Subject: [PATCH 05/49] Add basic systemd worker methods --- app/models/miq_worker.rb | 4 + app/models/miq_worker/systemd_worker.rb | 118 ++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 app/models/miq_worker/systemd_worker.rb diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index ae02f86ff74..715db3c493b 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -52,6 +52,10 @@ def self.workers workers_configured_count end + def self.singleton_worker? + maximum_workers_count.kind_of?(Integer) && maximum_workers_count == 1 + end + def self.workers_configured_count count = worker_settings[:count] if maximum_workers_count.kind_of?(Integer) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb new file mode 100644 index 00000000000..26d97e30e7a --- /dev/null +++ b/app/models/miq_worker/systemd_worker.rb @@ -0,0 +1,118 @@ +require "dbus/systemd" + +class MiqWorker + module SystemdWorker + extend ActiveSupport::Concern + + class_methods do + def supports_systemd? + true + end + end + + def ensure_systemd_files + File.write(target_file_path, target_file) unless target_file_path.exist? + File.write(service_file_path, unit_file) unless service_file_path.exist? + Dir.mkdir(service_config_path) unless service_config_path.exist? + File.write(service_config_file_path, service_settings_file) unless service_config_file_path.exist? + end + + def enable_systemd_unit + end + + def disable_systemd_unit + end + + def start_systemd_unit + end + + def stop_systemd_unit + end + + private + + def systemd + @systemd ||= DBus::Systemd::Manager.new + end + + def service_base_name + "#{minimal_class_name.underscore.tr("/", "_")}" + end + + def service_name + if self.class.singleton_worker? + "#{service_base_name}" + else + "#{service_base_name}@" + end + end + + def service_file_name + "#{service_name}.service" + end + + def slice_name + "cfme-#{service_name}.slice" + end + + def service_file_path + systemd_unit_dir.join(service_name) + end + + def service_config_name + "#{service_name}.d" + end + + def service_config_path + systemd_unit_dir.join(service_config_name) + end + + def service_config_file_path + service_config_path.join("settings.conf") + end + + def target_file_name + "#{service_base_name}.target" + end + + def target_file_path + systemd_unit_dir.join(target_file_name) + end + + def systemd_unit_dir + Pathname.new("/").join("etc", "systemd", "system") + end + + def target_file + <<~TARGET_FILE + [Unit] + PartOf=cfme.target + TARGET_FILE + end + + def unit_file + <<~UNIT_FILE + [Unit] + PartOf=#{target_file_name} + [Install] + WantedBy=#{target_file_name} + [Service] + #{unit_environment_variables.join("\n")} + WorkingDirectory=#{working_directory} + ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.class.name} --heartbeat' + Restart=always + Slice=#{slice_name} + UNIT_FILE + end + + def unit_environment_variables + # TODO get user's home dir dynamically + ["Environment=HOME=/root"] + end + + def working_directory + # TODO pull this dynamically + "/var/www/miq/vmdb" + end + end +end From de31730c30fee8ed6cc0c53173bb558753f73d46 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 9 Apr 2019 21:04:53 -0400 Subject: [PATCH 06/49] Start/stop systemd workers like container workers --- .../miq_server/worker_management/monitor/quiesce.rb | 8 +++++++- .../miq_server/worker_management/monitor/stop.rb | 2 ++ app/models/miq_worker.rb | 12 ++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/miq_server/worker_management/monitor/quiesce.rb b/app/models/miq_server/worker_management/monitor/quiesce.rb index ab4038ab82a..8fc0e3bb89c 100644 --- a/app/models/miq_server/worker_management/monitor/quiesce.rb +++ b/app/models/miq_server/worker_management/monitor/quiesce.rb @@ -36,7 +36,13 @@ def quiesce_workers_loop worker_monitor_poll = (@worker_monitor_settings[:poll] || 1.seconds).to_i_with_method miq_workers.each do |w| - MiqEnvironment::Command.is_podified? && w.containerized_worker? ? w.delete_container_objects : stop_worker(w) + if MiqEnvironment::Command.is_podified? && w.containerized_worker? + w.delete_container_objects + elsif w.systemd_worker? + w.disable_systemd_unit + else + stop_worker(w) + end end loop do diff --git a/app/models/miq_server/worker_management/monitor/stop.rb b/app/models/miq_server/worker_management/monitor/stop.rb index fd2bb3aa45b..f95b4275ec1 100644 --- a/app/models/miq_server/worker_management/monitor/stop.rb +++ b/app/models/miq_server/worker_management/monitor/stop.rb @@ -39,6 +39,8 @@ def stop_worker(worker, monitor_status = :waiting_for_stop, monitor_reason = nil if w.containerized_worker? w.stop_container + elsif w.systemd_worker? + w.stop_systemd_unit elsif w.respond_to?(:terminate) w.terminate else diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 715db3c493b..1a13aadb864 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -260,7 +260,7 @@ def self.create_worker_record(*params) end def self.start_worker(*params) - w = containerized_worker? ? init_worker_object(*params) : create_worker_record(*params) + w = containerized_worker? || systemd_worker? ? init_worker_object(*params) : create_worker_record(*params) w.start w end @@ -379,6 +379,8 @@ def systemd_worker? def start_runner if ENV['MIQ_SPAWN_WORKERS'] || !Process.respond_to?(:fork) start_runner_via_spawn + elsif systemd_worker? + start_runner_via_systemd elsif containerized_worker? start_runner_via_container else @@ -386,6 +388,12 @@ def start_runner end end + def start_runner_via_systemd + ensure_systemd_files + enable_systemd_unit + start_systemd_unit + end + def start_runner_via_container create_container_objects end @@ -434,7 +442,7 @@ def start_runner_via_spawn def start self.pid = start_runner - save unless containerized_worker? + save unless containerized_worker? || systemd_worker? msg = "Worker started: ID [#{id}], PID [#{pid}], GUID [#{guid}]" MiqEvent.raise_evm_event_queue(miq_server || MiqServer.my_server, "evm_worker_start", :event_details => msg, :type => self.class.name) From 1e8a2b7b6bd7528cc5e19c32cb01548aa4b1dbcd Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 08:22:33 -0400 Subject: [PATCH 07/49] Add service settings file --- app/models/miq_worker/systemd_worker.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index 26d97e30e7a..02756d4f1f4 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -110,6 +110,14 @@ def unit_environment_variables ["Environment=HOME=/root"] end + def service_settings_file + <<~WORKER_SETTINGS_FILE + [Service] + MemoryHigh=#{worker_settings[:memory_threshold].bytes} + TimeoutStartSec=#{worker_settings[:starting_timeout]} + TimeoutStopSec=#{worker_settings[:stopping_timeout]} + WORKER_SETTINGS_FILE + end def working_directory # TODO pull this dynamically "/var/www/miq/vmdb" From dd8ca62f37db0b08b197d06f4c1f5e4ffc0e44d5 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 08:34:24 -0400 Subject: [PATCH 08/49] Write out systemd files once not for every worker --- app/models/miq_worker.rb | 13 +- app/models/miq_worker/systemd_worker.rb | 172 ++++++++++++------------ 2 files changed, 97 insertions(+), 88 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 1a13aadb864..1ebf6356fe9 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -389,7 +389,6 @@ def start_runner end def start_runner_via_systemd - ensure_systemd_files enable_systemd_unit start_systemd_unit end @@ -566,16 +565,24 @@ def friendly_name delegate :normalized_type, :to => :class + def self.abbreviated_class_name + self.name.sub(/^ManageIQ::Providers::/, "") + end + def abbreviated_class_name - type.sub(/^ManageIQ::Providers::/, "") + self.class.abbreviated_class_name end - def minimal_class_name + def self.minimal_class_name abbreviated_class_name .sub(/Miq/, "") .sub(/Worker/, "") end + def minimal_class_name + self.class.minimal_class_name + end + def database_application_name zone = MiqServer.my_server.zone "MIQ|#{Process.pid}|#{miq_server.compressed_id}|#{compressed_id}|#{zone.compressed_id}|#{minimal_class_name}|#{zone.name}".truncate(64) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index 02756d4f1f4..0963591be5c 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -8,119 +8,121 @@ module SystemdWorker def supports_systemd? true end - end - def ensure_systemd_files - File.write(target_file_path, target_file) unless target_file_path.exist? - File.write(service_file_path, unit_file) unless service_file_path.exist? - Dir.mkdir(service_config_path) unless service_config_path.exist? - File.write(service_config_file_path, service_settings_file) unless service_config_file_path.exist? - end + def sync_workers + ensure_systemd_files + super + end - def enable_systemd_unit - end + def ensure_systemd_files + File.write(target_file_path, target_file) unless target_file_path.exist? + File.write(service_file_path, unit_file) unless service_file_path.exist? + Dir.mkdir(service_config_path) unless service_config_path.exist? + File.write(service_config_file_path, service_settings_file) unless service_config_file_path.exist? + end - def disable_systemd_unit - end + def service_base_name + "#{minimal_class_name.underscore.tr("/", "_")}" + end - def start_systemd_unit - end + def service_name + singleton_worker? ? "#{service_base_name}" : "#{service_base_name}@" + end - def stop_systemd_unit - end + def service_file_name + "#{service_name}.service" + end - private + def slice_name + "cfme-#{service_name}.slice" + end - def systemd - @systemd ||= DBus::Systemd::Manager.new - end + def service_file_path + systemd_unit_dir.join(service_name) + end - def service_base_name - "#{minimal_class_name.underscore.tr("/", "_")}" - end + def service_config_name + "#{service_name}.d" + end - def service_name - if self.class.singleton_worker? - "#{service_base_name}" - else - "#{service_base_name}@" + def service_config_path + systemd_unit_dir.join(service_config_name) end - end - def service_file_name - "#{service_name}.service" - end + def service_config_file_path + service_config_path.join("settings.conf") + end - def slice_name - "cfme-#{service_name}.slice" - end + def target_file_name + "#{service_base_name}.target" + end - def service_file_path - systemd_unit_dir.join(service_name) - end + def target_file_path + systemd_unit_dir.join(target_file_name) + end - def service_config_name - "#{service_name}.d" - end + def systemd_unit_dir + Pathname.new("/").join("etc", "systemd", "system") + end - def service_config_path - systemd_unit_dir.join(service_config_name) - end + def target_file + <<~TARGET_FILE + [Unit] + PartOf=cfme.target + TARGET_FILE + end - def service_config_file_path - service_config_path.join("settings.conf") - end + def unit_file + <<~UNIT_FILE + [Unit] + PartOf=#{target_file_name} + [Install] + WantedBy=#{target_file_name} + [Service] + #{unit_environment_variables.join("\n")} + WorkingDirectory=#{working_directory} + ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.class.name} --heartbeat' + Restart=always + Slice=#{slice_name} + UNIT_FILE + end - def target_file_name - "#{service_base_name}.target" - end + def unit_environment_variables + # TODO get user's home dir dynamically + ["Environment=HOME=/root"] + end - def target_file_path - systemd_unit_dir.join(target_file_name) - end + def service_settings_file + <<~WORKER_SETTINGS_FILE + [Service] + MemoryHigh=#{worker_settings[:memory_threshold].bytes} + TimeoutStartSec=#{worker_settings[:starting_timeout]} + TimeoutStopSec=#{worker_settings[:stopping_timeout]} + WORKER_SETTINGS_FILE + end - def systemd_unit_dir - Pathname.new("/").join("etc", "systemd", "system") + def working_directory + # TODO pull this dynamically + "/var/www/miq/vmdb" + end end - def target_file - <<~TARGET_FILE - [Unit] - PartOf=cfme.target - TARGET_FILE + def enable_systemd_unit end - def unit_file - <<~UNIT_FILE - [Unit] - PartOf=#{target_file_name} - [Install] - WantedBy=#{target_file_name} - [Service] - #{unit_environment_variables.join("\n")} - WorkingDirectory=#{working_directory} - ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.class.name} --heartbeat' - Restart=always - Slice=#{slice_name} - UNIT_FILE + def disable_systemd_unit end - def unit_environment_variables - # TODO get user's home dir dynamically - ["Environment=HOME=/root"] + def start_systemd_unit end - def service_settings_file - <<~WORKER_SETTINGS_FILE - [Service] - MemoryHigh=#{worker_settings[:memory_threshold].bytes} - TimeoutStartSec=#{worker_settings[:starting_timeout]} - TimeoutStopSec=#{worker_settings[:stopping_timeout]} - WORKER_SETTINGS_FILE + def stop_systemd_unit end - def working_directory - # TODO pull this dynamically - "/var/www/miq/vmdb" + + private + + def systemd + @systemd ||= DBus::Systemd::Manager.new end end end From 3df7edd2dd8c78656b746bae7a037f533c99eca6 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 08:51:04 -0400 Subject: [PATCH 09/49] Enable/Disable/Start/Stop units --- app/models/miq_worker.rb | 4 ++++ app/models/miq_worker/systemd_worker.rb | 24 ++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 1ebf6356fe9..2b8921df720 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -56,6 +56,10 @@ def self.singleton_worker? maximum_workers_count.kind_of?(Integer) && maximum_workers_count == 1 end + def singleton_worker? + self.class.singleton_worker? + end + def self.workers_configured_count count = worker_settings[:count] if maximum_workers_count.kind_of?(Integer) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index 0963591be5c..d9d2696eaf4 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -107,16 +107,20 @@ def working_directory end end - def enable_systemd_unit + def enable_systemd_unit(runtime: false, replace: true) + systemd.EnableUnitFiles([unit_name], runtime, replace) end - def disable_systemd_unit + def disable_systemd_unit(runtime: false) + systemd.DisableUnitFiles([unit_name], runtime) end - def start_systemd_unit + def start_systemd_unit(mode: "replace") + systemd.StartUnit(unit_name, mode) end - def stop_systemd_unit + def stop_systemd_unit(mode: "replace") + systemd.StopUnit(unit_name, mode) end private @@ -124,5 +128,17 @@ def stop_systemd_unit def systemd @systemd ||= DBus::Systemd::Manager.new end + + def service_base_name + self.class.service_base_name + end + + def unit_name + "#{service_base_name}#{unit_instance}.service" + end + + def unit_instance + singleton_worker? ? "" : "@#{guid}" + end end end From 4ce2a4e52f59e21ad3790b21dec4cbde1d794940 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 08:55:03 -0400 Subject: [PATCH 10/49] Create worker records for systemd workers --- app/models/miq_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 2b8921df720..b654638ae89 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -264,7 +264,7 @@ def self.create_worker_record(*params) end def self.start_worker(*params) - w = containerized_worker? || systemd_worker? ? init_worker_object(*params) : create_worker_record(*params) + w = containerized_worker? ? init_worker_object(*params) : create_worker_record(*params) w.start w end From 3346e0a78109e3d5abe77e424d5eb1db6b4c98ac Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 08:58:50 -0400 Subject: [PATCH 11/49] Fix service name --- app/models/miq_worker/systemd_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index d9d2696eaf4..715b91ae36f 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -38,7 +38,7 @@ def slice_name end def service_file_path - systemd_unit_dir.join(service_name) + systemd_unit_dir.join(service_file_name) end def service_config_name From 27445f388b8e6b949972bf834d75aa9d0be13c5a Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 09:00:42 -0400 Subject: [PATCH 12/49] Fix slice name --- app/models/miq_worker/systemd_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index 715b91ae36f..15bde367c16 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -34,7 +34,7 @@ def service_file_name end def slice_name - "cfme-#{service_name}.slice" + "cfme-#{service_base_name}.slice" end def service_file_path From 98425cf0a4127ad5a3e9035d76c7e347d878d145 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 09:18:38 -0400 Subject: [PATCH 13/49] Fix class name in run_single_worker --- app/models/miq_worker/systemd_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index 15bde367c16..bfd98b0ca44 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -81,7 +81,7 @@ def unit_file [Service] #{unit_environment_variables.join("\n")} WorkingDirectory=#{working_directory} - ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.class.name} --heartbeat' + ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.name} --heartbeat' Restart=always Slice=#{slice_name} UNIT_FILE From ca8ae4fb77ec290dc3cf74af438b8c5b62859c80 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 09:40:19 -0400 Subject: [PATCH 14/49] Allow systemd to be turned on/off from settings --- app/models/miq_worker/systemd_worker.rb | 2 +- config/settings.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index bfd98b0ca44..790db657cdf 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -6,7 +6,7 @@ module SystemdWorker class_methods do def supports_systemd? - true + worker_settings[:systemd_enabled] end def sync_workers diff --git a/config/settings.yml b/config/settings.yml index 6469d1fbd07..e27ca8f13be 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1149,6 +1149,7 @@ :restart_interval: 0.hours :starting_timeout: 10.minutes :stopping_timeout: 10.minutes + :systemd_enabled: false :embedded_ansible_worker: :starting_timeout: 20.minutes :poll: 10.seconds From d885d11a6fb015ff4c4cf233a55d59fe19a3e775 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 10:49:48 -0400 Subject: [PATCH 15/49] Add systemd worker concern --- app/models/miq_worker.rb | 5 ++--- app/models/miq_worker/systemd_worker.rb | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index b654638ae89..d31536ce262 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -2,6 +2,7 @@ class MiqWorker < ApplicationRecord include_concern 'ContainerCommon' + include_concern 'SystemdWorker' include UuidMixin before_destroy :log_destroy_of_worker_messages @@ -367,9 +368,7 @@ def containerized_worker? end def self.supports_systemd? - # Override this in a sub-class that supports being run as - # a systemd unit - false + worker_settings[:systemd_enabled] end def self.systemd_worker? diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index 790db657cdf..de48937a524 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -5,10 +5,6 @@ module SystemdWorker extend ActiveSupport::Concern class_methods do - def supports_systemd? - worker_settings[:systemd_enabled] - end - def sync_workers ensure_systemd_files super From 735407a18bc95dd3874f1b01f0aecbb3fb7803f6 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 11:48:35 -0400 Subject: [PATCH 16/49] Use guid from systemd unit instance --- app/models/miq_worker/systemd_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index de48937a524..ec2ed750bfa 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -77,7 +77,7 @@ def unit_file [Service] #{unit_environment_variables.join("\n")} WorkingDirectory=#{working_directory} - ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.name} --heartbeat' + ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.name} --heartbeat --guid=%i' Restart=always Slice=#{slice_name} UNIT_FILE From 980ecdb4023936d8c676d104693df911ac32d63e Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 11:52:23 -0400 Subject: [PATCH 17/49] Fix ensure_systemd_files --- app/models/miq_worker.rb | 2 ++ app/models/miq_worker/systemd_worker.rb | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index d31536ce262..a1f9dc083e6 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -135,6 +135,8 @@ def self.enough_resource_to_start_worker? end def self.sync_workers + ensure_systemd_files if systemd_worker? + w = include_stopping_workers_on_synchronize ? find_alive : find_current_or_starting current = w.length desired = self.has_required_role? ? workers : 0 diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_worker.rb index ec2ed750bfa..5f8b07e373f 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_worker.rb @@ -5,11 +5,6 @@ module SystemdWorker extend ActiveSupport::Concern class_methods do - def sync_workers - ensure_systemd_files - super - end - def ensure_systemd_files File.write(target_file_path, target_file) unless target_file_path.exist? File.write(service_file_path, unit_file) unless service_file_path.exist? From b73e920f2d8eac8569a202818f1280759107684b Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 13:31:51 -0400 Subject: [PATCH 18/49] Stop and disable systemd workers on shutdown --- app/models/miq_server/worker_management/monitor/quiesce.rb | 1 + app/models/miq_server/worker_management/monitor/stop.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/models/miq_server/worker_management/monitor/quiesce.rb b/app/models/miq_server/worker_management/monitor/quiesce.rb index 8fc0e3bb89c..b650fa16c8c 100644 --- a/app/models/miq_server/worker_management/monitor/quiesce.rb +++ b/app/models/miq_server/worker_management/monitor/quiesce.rb @@ -39,6 +39,7 @@ def quiesce_workers_loop if MiqEnvironment::Command.is_podified? && w.containerized_worker? w.delete_container_objects elsif w.systemd_worker? + w.stop_systemd_unit w.disable_systemd_unit else stop_worker(w) diff --git a/app/models/miq_server/worker_management/monitor/stop.rb b/app/models/miq_server/worker_management/monitor/stop.rb index f95b4275ec1..69a8b56c624 100644 --- a/app/models/miq_server/worker_management/monitor/stop.rb +++ b/app/models/miq_server/worker_management/monitor/stop.rb @@ -41,6 +41,7 @@ def stop_worker(worker, monitor_status = :waiting_for_stop, monitor_reason = nil w.stop_container elsif w.systemd_worker? w.stop_systemd_unit + w.disable_systemd_unit elsif w.respond_to?(:terminate) w.terminate else From a80294396cc350bc1af88167a7d4913169a966df Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 14:21:55 -0400 Subject: [PATCH 19/49] Rename SystemdWorker -> SystemdCommon --- app/models/miq_worker.rb | 2 +- app/models/miq_worker/{systemd_worker.rb => systemd_common.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/models/miq_worker/{systemd_worker.rb => systemd_common.rb} (99%) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index a1f9dc083e6..d79c8d2f006 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -2,7 +2,7 @@ class MiqWorker < ApplicationRecord include_concern 'ContainerCommon' - include_concern 'SystemdWorker' + include_concern 'SystemdCommon' include UuidMixin before_destroy :log_destroy_of_worker_messages diff --git a/app/models/miq_worker/systemd_worker.rb b/app/models/miq_worker/systemd_common.rb similarity index 99% rename from app/models/miq_worker/systemd_worker.rb rename to app/models/miq_worker/systemd_common.rb index 5f8b07e373f..6aa306274b9 100644 --- a/app/models/miq_worker/systemd_worker.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -1,7 +1,7 @@ require "dbus/systemd" class MiqWorker - module SystemdWorker + module SystemdCommon extend ActiveSupport::Concern class_methods do From 5474bf977267a8b30b238dabcfa9a813821a6efd Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 15:12:48 -0400 Subject: [PATCH 20/49] Prepend Environment to env vars automatically --- app/models/miq_worker/systemd_common.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 6aa306274b9..55e461f62ef 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -53,7 +53,7 @@ def target_file_path end def systemd_unit_dir - Pathname.new("/").join("etc", "systemd", "system") + Pathname.new("/etc/systemd/system") end def target_file @@ -70,7 +70,7 @@ def unit_file [Install] WantedBy=#{target_file_name} [Service] - #{unit_environment_variables.join("\n")} + #{service_environment_variables.map { |env_var| "Environment=#{env_var}" }.join("\n")} WorkingDirectory=#{working_directory} ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.name} --heartbeat --guid=%i' Restart=always @@ -78,9 +78,9 @@ def unit_file UNIT_FILE end - def unit_environment_variables + def service_environment_variables # TODO get user's home dir dynamically - ["Environment=HOME=/root"] + ["HOME=/root"] end def service_settings_file From 171e5575c8c8cd2802488007cd3d61be007d5adf Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 15:19:14 -0400 Subject: [PATCH 21/49] Split out ExecStart into a method to allow override --- app/models/miq_worker/systemd_common.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 55e461f62ef..46fdc065f6b 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -72,12 +72,20 @@ def unit_file [Service] #{service_environment_variables.map { |env_var| "Environment=#{env_var}" }.join("\n")} WorkingDirectory=#{working_directory} - ExecStart=/bin/bash -lc 'exec ruby lib/workers/bin/run_single_worker.rb #{self.name} --heartbeat --guid=%i' + ExecStart=/bin/bash -lc '#{exec_start}' Restart=always Slice=#{slice_name} UNIT_FILE end + def exec_start + "exec ruby lib/workers/bin/run_single_worker.rb #{self.name} #{run_single_worker_args}" + end + + def run_single_worker_args + "--heartbeat --guid=%i" + end + def service_environment_variables # TODO get user's home dir dynamically ["HOME=/root"] From 2756e3a49be2c693c391c305b1533bae763a43bc Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2019 15:49:23 -0400 Subject: [PATCH 22/49] Move service env vars to settings file --- app/models/miq_worker/systemd_common.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 46fdc065f6b..86b5f809dc2 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -70,7 +70,7 @@ def unit_file [Install] WantedBy=#{target_file_name} [Service] - #{service_environment_variables.map { |env_var| "Environment=#{env_var}" }.join("\n")} + Environment=HOME=/root WorkingDirectory=#{working_directory} ExecStart=/bin/bash -lc '#{exec_start}' Restart=always @@ -78,6 +78,11 @@ def unit_file UNIT_FILE end + def working_directory + # TODO pull this dynamically + "/var/www/miq/vmdb" + end + def exec_start "exec ruby lib/workers/bin/run_single_worker.rb #{self.name} #{run_single_worker_args}" end @@ -87,23 +92,19 @@ def run_single_worker_args end def service_environment_variables - # TODO get user's home dir dynamically - ["HOME=/root"] + # Override this in a child class to add env vars + [] end def service_settings_file <<~WORKER_SETTINGS_FILE [Service] + #{service_environment_variables.map { |env_var| "Environment=#{env_var}" }.join("\n")} MemoryHigh=#{worker_settings[:memory_threshold].bytes} TimeoutStartSec=#{worker_settings[:starting_timeout]} TimeoutStopSec=#{worker_settings[:stopping_timeout]} WORKER_SETTINGS_FILE end - - def working_directory - # TODO pull this dynamically - "/var/www/miq/vmdb" - end end def enable_systemd_unit(runtime: false, replace: true) From e9b1b0b53b5cd037d1e1ce604910e03ce4012b7e Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 11 Apr 2019 12:01:14 -0400 Subject: [PATCH 23/49] Make systemd-journal gem optional --- Gemfile | 4 ++++ lib/vmdb/loggers.rb | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 0da56e9f4b4..6a7841bb24e 100644 --- a/Gemfile +++ b/Gemfile @@ -132,6 +132,10 @@ group :qpid_proton, :optional => true do gem "qpid_proton", "~>0.26.0", :require => false end +group :systemd_journal, :optional => true do + gem "systemd-journal", "~>1.4.0", :require => false +end + group :openshift, :manageiq_default do manageiq_plugin "manageiq-providers-openshift" end diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index d4f430d75bb..76d0ea5ba2f 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -21,7 +21,7 @@ def self.init def self.apply_config(config) apply_config_value(config, $log, :level) - apply_config_value(config, $journald_log, :level) + apply_config_value(config, $journald_log, :level) if MiqEnvironment::Command.supports_systemd? apply_config_value(config, $rails_log, :level_rails) apply_config_value(config, $ansible_tower_log, :level_ansible_tower) apply_config_value(config, $api_log, :level_api) @@ -48,7 +48,11 @@ def self.create_loggers $audit_log = AuditLogger.new(path_dir.join("audit.log")) $container_log = ContainerLogger.new - $journald_log = ManageIQ::Loggers::Journald.new + if MiqEnvironment::Command.supports_systemd? + require "manageiq/loggers/journald" + $journald_log = ManageIQ::Loggers::Journald.new + end + $log = create_multicast_logger(path_dir.join("evm.log")) $rails_log = create_multicast_logger(path_dir.join("#{Rails.env}.log")) $api_log = create_multicast_logger(path_dir.join("api.log")) @@ -77,7 +81,7 @@ def self.create_loggers def self.create_multicast_logger(log_file_path, logger_class = VMDBLogger) logger_class.new(log_file_path).tap do |logger| logger.extend(ActiveSupport::Logger.broadcast($container_log)) if ENV["CONTAINER"] - logger.extend(ActiveSupport::Logger.broadcast($journald_log)) if MiqEnvironment::Command.supports_systemd? + logger.extend(ActiveSupport::Logger.broadcast($journald_log)) if MiqEnvironment::Command.supports_systemd? end end private_class_method :create_multicast_logger From a40c47ab422e0b33e0ae3247a3ea4c13b22a2be6 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 11 Apr 2019 15:21:51 -0400 Subject: [PATCH 24/49] Ensure systemd files for other types fo workers --- app/models/mixins/miq_web_server_worker_mixin.rb | 2 ++ app/models/mixins/per_ems_worker_mixin.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/mixins/miq_web_server_worker_mixin.rb b/app/models/mixins/miq_web_server_worker_mixin.rb index 707c96019f6..36bd144bf9a 100644 --- a/app/models/mixins/miq_web_server_worker_mixin.rb +++ b/app/models/mixins/miq_web_server_worker_mixin.rb @@ -50,6 +50,8 @@ def build_uri(port) end def sync_workers + ensure_systemd_files if systemd_worker? + # TODO: add an at_exit to remove all registered ports and gracefully stop apache self.registered_ports ||= [] diff --git a/app/models/mixins/per_ems_worker_mixin.rb b/app/models/mixins/per_ems_worker_mixin.rb index e3e392e3c72..3443f1ed86b 100644 --- a/app/models/mixins/per_ems_worker_mixin.rb +++ b/app/models/mixins/per_ems_worker_mixin.rb @@ -33,6 +33,8 @@ def desired_queue_names end def sync_workers + ensure_systemd_files if systemd_worker? + ws = find_current_or_starting current = ws.collect(&:queue_name).sort desired = self.has_required_role? ? desired_queue_names.sort : [] From fecd47ddb0db9e3e74dabc4c005387f83c8b71f2 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 11 Apr 2019 15:47:06 -0400 Subject: [PATCH 25/49] Only apply config if journald_log present --- lib/vmdb/loggers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index 76d0ea5ba2f..944fc43b8c7 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -21,7 +21,7 @@ def self.init def self.apply_config(config) apply_config_value(config, $log, :level) - apply_config_value(config, $journald_log, :level) if MiqEnvironment::Command.supports_systemd? + apply_config_value(config, $journald_log, :level) if $journald_log apply_config_value(config, $rails_log, :level_rails) apply_config_value(config, $ansible_tower_log, :level_ansible_tower) apply_config_value(config, $api_log, :level_api) From c2a24a67fd67d1f280fa431612167d270e049a12 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 11 Apr 2019 15:52:03 -0400 Subject: [PATCH 26/49] Ensure systemd files before sync_workers --- app/models/miq_server/worker_management/monitor.rb | 1 + app/models/miq_worker.rb | 2 -- app/models/mixins/miq_web_server_worker_mixin.rb | 2 -- app/models/mixins/per_ems_worker_mixin.rb | 2 -- 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/miq_server/worker_management/monitor.rb b/app/models/miq_server/worker_management/monitor.rb index eaa78d53fb0..c13bc816dea 100644 --- a/app/models/miq_server/worker_management/monitor.rb +++ b/app/models/miq_server/worker_management/monitor.rb @@ -50,6 +50,7 @@ def sync_workers self.class.monitor_class_names.each do |class_name| begin c = class_name.constantize + c.ensure_systemd_files if c.systemd_worker? result[c.name] = c.sync_workers result[c.name][:adds].each { |pid| worker_add(pid) unless pid.nil? } rescue => error diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index d79c8d2f006..6e204911fb5 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -135,8 +135,6 @@ def self.enough_resource_to_start_worker? end def self.sync_workers - ensure_systemd_files if systemd_worker? - w = include_stopping_workers_on_synchronize ? find_alive : find_current_or_starting current = w.length desired = self.has_required_role? ? workers : 0 diff --git a/app/models/mixins/miq_web_server_worker_mixin.rb b/app/models/mixins/miq_web_server_worker_mixin.rb index 36bd144bf9a..707c96019f6 100644 --- a/app/models/mixins/miq_web_server_worker_mixin.rb +++ b/app/models/mixins/miq_web_server_worker_mixin.rb @@ -50,8 +50,6 @@ def build_uri(port) end def sync_workers - ensure_systemd_files if systemd_worker? - # TODO: add an at_exit to remove all registered ports and gracefully stop apache self.registered_ports ||= [] diff --git a/app/models/mixins/per_ems_worker_mixin.rb b/app/models/mixins/per_ems_worker_mixin.rb index 3443f1ed86b..e3e392e3c72 100644 --- a/app/models/mixins/per_ems_worker_mixin.rb +++ b/app/models/mixins/per_ems_worker_mixin.rb @@ -33,8 +33,6 @@ def desired_queue_names end def sync_workers - ensure_systemd_files if systemd_worker? - ws = find_current_or_starting current = ws.collect(&:queue_name).sort desired = self.has_required_role? ? desired_queue_names.sort : [] From 6e3444e947a841703e1f5184c06fbade33b00381 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 25 Apr 2019 17:42:14 -0400 Subject: [PATCH 27/49] Check for $journald_log.nil? instead of MiqEnvironment --- lib/vmdb/loggers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index 944fc43b8c7..cdca91fbabc 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -81,7 +81,7 @@ def self.create_loggers def self.create_multicast_logger(log_file_path, logger_class = VMDBLogger) logger_class.new(log_file_path).tap do |logger| logger.extend(ActiveSupport::Logger.broadcast($container_log)) if ENV["CONTAINER"] - logger.extend(ActiveSupport::Logger.broadcast($journald_log)) if MiqEnvironment::Command.supports_systemd? + logger.extend(ActiveSupport::Logger.broadcast($journald_log)) if $journald_log end end private_class_method :create_multicast_logger From 646293cc2bfa203f182137a3d474b5aff8198496 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 25 Apr 2019 17:45:33 -0400 Subject: [PATCH 28/49] Delay load dbus-systemd --- app/models/miq_worker/systemd_common.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 86b5f809dc2..418f0aa21b0 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -1,5 +1,3 @@ -require "dbus/systemd" - class MiqWorker module SystemdCommon extend ActiveSupport::Concern @@ -126,7 +124,10 @@ def stop_systemd_unit(mode: "replace") private def systemd - @systemd ||= DBus::Systemd::Manager.new + @systemd ||= begin + require "dbus/systemd" + DBus::Systemd::Manager.new + end end def service_base_name From de6d3e72e6e35f8a63f5190681936fc39c9122a0 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 08:41:06 -0400 Subject: [PATCH 29/49] Move dbus-systemd to an optional systemd group --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 6a7841bb24e..78283341328 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,6 @@ gem "byebug", :require => false gem "color", "~>1.8" gem "config", "~>1.6.0", :require => false gem "dalli", "=2.7.6", :require => false -gem "dbus-systemd", "~>1.1.0", :require => false gem "default_value_for", "~>3.0.3" gem "docker-api", "~>1.33.6", :require => false gem "elif", "=0.1.0", :require => false @@ -132,7 +131,8 @@ group :qpid_proton, :optional => true do gem "qpid_proton", "~>0.26.0", :require => false end -group :systemd_journal, :optional => true do +group :systemd, :optional => true do + gem "dbus-systemd", "~>1.1.0", :require => false gem "systemd-journal", "~>1.4.0", :require => false end From 22310f9f9b57a19c1819f1c5928d3d28bc00a2c3 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 08:48:49 -0400 Subject: [PATCH 30/49] Use containerized_worker? in quiesce_workers_loop --- app/models/miq_server/worker_management/monitor/quiesce.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_server/worker_management/monitor/quiesce.rb b/app/models/miq_server/worker_management/monitor/quiesce.rb index b650fa16c8c..5ac4db7f0ac 100644 --- a/app/models/miq_server/worker_management/monitor/quiesce.rb +++ b/app/models/miq_server/worker_management/monitor/quiesce.rb @@ -36,7 +36,7 @@ def quiesce_workers_loop worker_monitor_poll = (@worker_monitor_settings[:poll] || 1.seconds).to_i_with_method miq_workers.each do |w| - if MiqEnvironment::Command.is_podified? && w.containerized_worker? + if w.containerized_worker? w.delete_container_objects elsif w.systemd_worker? w.stop_systemd_unit From 7027e0c84dca65da2884035833f0b3b4e9b89075 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 08:50:56 -0400 Subject: [PATCH 31/49] Remove redundant self from abbreviated_class_name --- app/models/miq_worker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 6e204911fb5..2d181b863fc 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -444,7 +444,7 @@ def start_runner_via_spawn def start self.pid = start_runner - save unless containerized_worker? || systemd_worker? + save if !containerized_worker? && !systemd_worker? msg = "Worker started: ID [#{id}], PID [#{pid}], GUID [#{guid}]" MiqEvent.raise_evm_event_queue(miq_server || MiqServer.my_server, "evm_worker_start", :event_details => msg, :type => self.class.name) @@ -569,7 +569,7 @@ def friendly_name delegate :normalized_type, :to => :class def self.abbreviated_class_name - self.name.sub(/^ManageIQ::Providers::/, "") + name.sub(/^ManageIQ::Providers::/, "") end def abbreviated_class_name From cbaf512e144a1d7636f3cf25f86f5fca9023ab94 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 08:53:36 -0400 Subject: [PATCH 32/49] Don't interpolate strings --- app/models/miq_worker/systemd_common.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 418f0aa21b0..eaeb9ad975b 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -11,11 +11,15 @@ def ensure_systemd_files end def service_base_name - "#{minimal_class_name.underscore.tr("/", "_")}" + minimal_class_name.underscore.tr("/", "_") + end + + def slice_base_name + "miq" end def service_name - singleton_worker? ? "#{service_base_name}" : "#{service_base_name}@" + singleton_worker? ? service_base_name : "#{service_base_name}@" end def service_file_name @@ -23,7 +27,7 @@ def service_file_name end def slice_name - "cfme-#{service_base_name}.slice" + "#{slice_base_name}-#{service_base_name}.slice" end def service_file_path @@ -77,7 +81,7 @@ def unit_file end def working_directory - # TODO pull this dynamically + # TODO: pull this dynamically "/var/www/miq/vmdb" end From cea02f06c8476340e8817f8fdce0ec57048ec639 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 09:01:39 -0400 Subject: [PATCH 33/49] Remove redundant self from systemd_common --- app/models/miq_worker/systemd_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index eaeb9ad975b..6d6b70ca9aa 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -86,7 +86,7 @@ def working_directory end def exec_start - "exec ruby lib/workers/bin/run_single_worker.rb #{self.name} #{run_single_worker_args}" + "exec ruby lib/workers/bin/run_single_worker.rb #{name} #{run_single_worker_args}" end def run_single_worker_args From 3c4a56c7190521ca77dd94a929233724caf66091 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 09:06:43 -0400 Subject: [PATCH 34/49] Add helper methods to start/stop systemd worker --- .../miq_server/worker_management/monitor/quiesce.rb | 3 +-- .../miq_server/worker_management/monitor/stop.rb | 3 +-- app/models/miq_worker.rb | 7 +------ app/models/miq_worker/systemd_common.rb | 10 ++++++++++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/models/miq_server/worker_management/monitor/quiesce.rb b/app/models/miq_server/worker_management/monitor/quiesce.rb index 5ac4db7f0ac..dc47e23615d 100644 --- a/app/models/miq_server/worker_management/monitor/quiesce.rb +++ b/app/models/miq_server/worker_management/monitor/quiesce.rb @@ -39,8 +39,7 @@ def quiesce_workers_loop if w.containerized_worker? w.delete_container_objects elsif w.systemd_worker? - w.stop_systemd_unit - w.disable_systemd_unit + w.stop_systemd_worker else stop_worker(w) end diff --git a/app/models/miq_server/worker_management/monitor/stop.rb b/app/models/miq_server/worker_management/monitor/stop.rb index 69a8b56c624..7d858ec79b9 100644 --- a/app/models/miq_server/worker_management/monitor/stop.rb +++ b/app/models/miq_server/worker_management/monitor/stop.rb @@ -40,8 +40,7 @@ def stop_worker(worker, monitor_status = :waiting_for_stop, monitor_reason = nil if w.containerized_worker? w.stop_container elsif w.systemd_worker? - w.stop_systemd_unit - w.disable_systemd_unit + w.stop_systemd_worker elsif w.respond_to?(:terminate) w.terminate else diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 2d181b863fc..1e10213ee80 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -383,7 +383,7 @@ def start_runner if ENV['MIQ_SPAWN_WORKERS'] || !Process.respond_to?(:fork) start_runner_via_spawn elsif systemd_worker? - start_runner_via_systemd + start_systemd_worker elsif containerized_worker? start_runner_via_container else @@ -391,11 +391,6 @@ def start_runner end end - def start_runner_via_systemd - enable_systemd_unit - start_systemd_unit - end - def start_runner_via_container create_container_objects end diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 6d6b70ca9aa..d79fb85d41c 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -109,6 +109,16 @@ def service_settings_file end end + def start_systemd_worker + enable_systemd_unit + start_systemd_unit + end + + def stop_systemd_worker + stop_systemd_unit + disable_systemd_unit + end + def enable_systemd_unit(runtime: false, replace: true) systemd.EnableUnitFiles([unit_name], runtime, replace) end From 6aaf89145175b47da5f223248ef3f6388d178cc0 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 09:25:04 -0400 Subject: [PATCH 35/49] Use mkdir_p for systemd config dir --- app/models/miq_worker/systemd_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index d79fb85d41c..53a26e179fd 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -6,7 +6,7 @@ module SystemdCommon def ensure_systemd_files File.write(target_file_path, target_file) unless target_file_path.exist? File.write(service_file_path, unit_file) unless service_file_path.exist? - Dir.mkdir(service_config_path) unless service_config_path.exist? + FileUtils.mkdir_p(service_config_path) unless service_config_path.exist? File.write(service_config_file_path, service_settings_file) unless service_config_file_path.exist? end From c9c8346821b1c20568e49dbb274cde92b04a86ab Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 09:30:34 -0400 Subject: [PATCH 36/49] Use Pathname#write for unit files --- app/models/miq_worker/systemd_common.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 53a26e179fd..6ab1017ebe2 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -4,10 +4,10 @@ module SystemdCommon class_methods do def ensure_systemd_files - File.write(target_file_path, target_file) unless target_file_path.exist? - File.write(service_file_path, unit_file) unless service_file_path.exist? + target_file_path.write(target_file) unless target_file_path.exist? + service_file_path.write(unit_file) unless service_file_path.exist? FileUtils.mkdir_p(service_config_path) unless service_config_path.exist? - File.write(service_config_file_path, service_settings_file) unless service_config_file_path.exist? + service_config_file_path.write(service_settings_file) unless service_config_file_path.exist? end def service_base_name From a7cf6da4f841cc537f8b090820a65c0aadf41dd3 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 09:52:02 -0400 Subject: [PATCH 37/49] Freeze constants in MiqEnvironment --- lib/miq_environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/miq_environment.rb b/lib/miq_environment.rb index 74a8594bbda..db501f58448 100644 --- a/lib/miq_environment.rb +++ b/lib/miq_environment.rb @@ -2,7 +2,7 @@ module MiqEnvironment class Command - EVM_KNOWN_COMMANDS = %w(apachectl memcached memcached-tool nohup service systemctl) + EVM_KNOWN_COMMANDS = %w[apachectl memcached memcached-tool nohup service systemctl].freeze def self.supports_memcached? return @supports_memcached unless @supports_memcached.nil? From 2b9595083778bac74b81c305a193264020e853df Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 09:57:03 -0400 Subject: [PATCH 38/49] Fix service conf dir path --- app/models/miq_worker/systemd_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 6ab1017ebe2..4f372ab6c31 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -35,7 +35,7 @@ def service_file_path end def service_config_name - "#{service_name}.d" + "#{service_file_name}.d" end def service_config_path From 3ade53c722b22c10b95fb2dd0900141042c10697 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 10:16:31 -0400 Subject: [PATCH 39/49] Replace cfme.target with miq.target --- app/models/miq_worker/systemd_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 4f372ab6c31..13e8c08a942 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -61,7 +61,7 @@ def systemd_unit_dir def target_file <<~TARGET_FILE [Unit] - PartOf=cfme.target + PartOf=miq.target TARGET_FILE end From efed6fc53b4d47f99d78f500680ccced57223be4 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 13:20:31 -0400 Subject: [PATCH 40/49] Fix handling of required_roles being a Proc --- lib/workers/bin/run_single_worker.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/workers/bin/run_single_worker.rb b/lib/workers/bin/run_single_worker.rb index 04bfae84ebe..f9193561c21 100644 --- a/lib/workers/bin/run_single_worker.rb +++ b/lib/workers/bin/run_single_worker.rb @@ -63,9 +63,8 @@ require File.expand_path("../../../config/environment", __dir__) worker_class = worker_class.constantize -missing_roles = ServerRole.where(:name => worker_class.required_roles) - MiqServer.my_server.active_roles -unless missing_roles.empty? - STDERR.puts "ERR: Server roles are not sufficient for `#{worker_class}` worker. Missing: #{missing_roles.collect(&:name)}" +unless worker_class.has_required_role? + STDERR.puts "ERR: Server roles are not sufficient for `#{worker_class}` worker." exit 1 unless options[:force] end From 802ca51c4c372d171291f6fe727c9ff17844b86d Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 13:34:13 -0400 Subject: [PATCH 41/49] Allow per-unit instance settings --- app/models/miq_worker/systemd_common.rb | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 13e8c08a942..0fc4bd6c1e1 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -111,6 +111,7 @@ def service_settings_file def start_systemd_worker enable_systemd_unit + write_unit_settings_file unless singleton_worker? start_systemd_unit end @@ -155,5 +156,30 @@ def unit_name def unit_instance singleton_worker? ? "" : "@#{guid}" end + + def write_unit_settings_file + return unless unit_config_file.present? + + FileUtils.mkdir_p(unit_config_path) unless unit_config_path.exist? + unit_config_file_path.write(unit_config_file) unless unit_config_file_path.exist? + end + + def unit_config_name + "#{unit_name}.d" + end + + def unit_config_path + self.class.systemd_unit_dir.join(unit_config_name) + end + + def unit_config_file_path + unit_config_path.join("settings.conf") + end + + def unit_config_file + # Override this in a sub-class if the specific instance needs + # any additional config + nil + end end end From 4e7a3c0a660289e17f353d58b50bec83a449743d Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 13:35:59 -0400 Subject: [PATCH 42/49] Send EMS_ID for per_ems_workers --- app/models/mixins/per_ems_worker_mixin.rb | 7 +++++++ lib/workers/bin/run_single_worker.rb | 2 ++ 2 files changed, 9 insertions(+) diff --git a/app/models/mixins/per_ems_worker_mixin.rb b/app/models/mixins/per_ems_worker_mixin.rb index e3e392e3c72..36d4829abd4 100644 --- a/app/models/mixins/per_ems_worker_mixin.rb +++ b/app/models/mixins/per_ems_worker_mixin.rb @@ -135,4 +135,11 @@ def ext_management_system def worker_options super.merge(:ems_id => ems_id) end + + def unit_config_file + <<~UNIT_CONFIG_FILE + [Service] + Environment=EMS_ID=#{ems_id} + UNIT_CONFIG_FILE + end end diff --git a/lib/workers/bin/run_single_worker.rb b/lib/workers/bin/run_single_worker.rb index f9193561c21..4d982a2abb2 100644 --- a/lib/workers/bin/run_single_worker.rb +++ b/lib/workers/bin/run_single_worker.rb @@ -60,6 +60,8 @@ ENV["DISABLE_MIQ_WORKER_HEARTBEAT"] ||= options[:heartbeat] ? nil : '1' ENV["BUNDLER_GROUPS"] = MIQ_WORKER_TYPES[worker_class].join(',') +options[:ems_id] ||= ENV["EMS_ID"] + require File.expand_path("../../../config/environment", __dir__) worker_class = worker_class.constantize From a7c686b3e52d2a7bd80821ee6d957413b73f9d87 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 14:11:35 -0400 Subject: [PATCH 43/49] Remove unit instance settings files on shutdown --- app/models/miq_worker/systemd_common.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 0fc4bd6c1e1..9a28a7939fb 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -111,12 +111,13 @@ def service_settings_file def start_systemd_worker enable_systemd_unit - write_unit_settings_file unless singleton_worker? + write_unit_settings_file start_systemd_unit end def stop_systemd_worker stop_systemd_unit + cleanup_unit_settings_file disable_systemd_unit end @@ -158,12 +159,22 @@ def unit_instance end def write_unit_settings_file - return unless unit_config_file.present? + # Only write a per-instance settings file if the worker is not a singleton, + # otherwise all settings could go to the main settings file (also the file + # paths would collide). + return if singleton_worker? || unit_config_file.blank? - FileUtils.mkdir_p(unit_config_path) unless unit_config_path.exist? + FileUtils.mkdir_p(unit_config_path) unless unit_config_path.exist? unit_config_file_path.write(unit_config_file) unless unit_config_file_path.exist? end + def cleanup_unit_settings_file + return if singleton_worker? + + unit_config_file_path.delete if unit_config_file_path.exist? + unit_config_path.delete if unit_config_path.exist? + end + def unit_config_name "#{unit_name}.d" end From 48c0928cb5ce4690a8935f4022bb73b845119013 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 29 Apr 2019 16:05:52 -0400 Subject: [PATCH 44/49] Settings always at the unit instance and rename override.conf --- app/models/miq_worker/systemd_common.rb | 54 +++++++---------------- app/models/mixins/per_ems_worker_mixin.rb | 7 +-- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 9a28a7939fb..728b5cdae6a 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -6,8 +6,6 @@ module SystemdCommon def ensure_systemd_files target_file_path.write(target_file) unless target_file_path.exist? service_file_path.write(unit_file) unless service_file_path.exist? - FileUtils.mkdir_p(service_config_path) unless service_config_path.exist? - service_config_file_path.write(service_settings_file) unless service_config_file_path.exist? end def service_base_name @@ -34,18 +32,6 @@ def service_file_path systemd_unit_dir.join(service_file_name) end - def service_config_name - "#{service_file_name}.d" - end - - def service_config_path - systemd_unit_dir.join(service_config_name) - end - - def service_config_file_path - service_config_path.join("settings.conf") - end - def target_file_name "#{service_base_name}.target" end @@ -72,7 +58,6 @@ def unit_file [Install] WantedBy=#{target_file_name} [Service] - Environment=HOME=/root WorkingDirectory=#{working_directory} ExecStart=/bin/bash -lc '#{exec_start}' Restart=always @@ -92,21 +77,6 @@ def exec_start def run_single_worker_args "--heartbeat --guid=%i" end - - def service_environment_variables - # Override this in a child class to add env vars - [] - end - - def service_settings_file - <<~WORKER_SETTINGS_FILE - [Service] - #{service_environment_variables.map { |env_var| "Environment=#{env_var}" }.join("\n")} - MemoryHigh=#{worker_settings[:memory_threshold].bytes} - TimeoutStartSec=#{worker_settings[:starting_timeout]} - TimeoutStopSec=#{worker_settings[:stopping_timeout]} - WORKER_SETTINGS_FILE - end end def start_systemd_worker @@ -159,18 +129,11 @@ def unit_instance end def write_unit_settings_file - # Only write a per-instance settings file if the worker is not a singleton, - # otherwise all settings could go to the main settings file (also the file - # paths would collide). - return if singleton_worker? || unit_config_file.blank? - FileUtils.mkdir_p(unit_config_path) unless unit_config_path.exist? unit_config_file_path.write(unit_config_file) unless unit_config_file_path.exist? end def cleanup_unit_settings_file - return if singleton_worker? - unit_config_file_path.delete if unit_config_file_path.exist? unit_config_path.delete if unit_config_path.exist? end @@ -184,13 +147,26 @@ def unit_config_path end def unit_config_file_path - unit_config_path.join("settings.conf") + unit_config_path.join("override.conf") end def unit_config_file # Override this in a sub-class if the specific instance needs # any additional config - nil + <<~UNIT_CONFIG_FILE + [Service] + MemoryHigh=#{worker_settings[:memory_threshold].bytes} + TimeoutStartSec=#{worker_settings[:starting_timeout]} + TimeoutStopSec=#{worker_settings[:stopping_timeout]} + #{unit_environment_variables.map { |env_var| "Environment=#{env_var}" }.join("\n")} + UNIT_CONFIG_FILE + end + + def unit_environment_variables + # Override this in a child class to add env vars + [ + "HOME=/root" + ] end end end diff --git a/app/models/mixins/per_ems_worker_mixin.rb b/app/models/mixins/per_ems_worker_mixin.rb index 36d4829abd4..cef01cedc7d 100644 --- a/app/models/mixins/per_ems_worker_mixin.rb +++ b/app/models/mixins/per_ems_worker_mixin.rb @@ -136,10 +136,7 @@ def worker_options super.merge(:ems_id => ems_id) end - def unit_config_file - <<~UNIT_CONFIG_FILE - [Service] - Environment=EMS_ID=#{ems_id} - UNIT_CONFIG_FILE + def unit_environment_variables + super << "EMS_ID=#{ems_id}" end end From 927c7ff1e79a808d5751593cd76b1075c3631ece Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 13 May 2019 13:29:14 -0400 Subject: [PATCH 45/49] Rename singleton_worker? method to scalable? --- app/models/miq_worker.rb | 6 +++--- app/models/miq_worker/systemd_common.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 1e10213ee80..55fe3c0eda1 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -53,12 +53,12 @@ def self.workers workers_configured_count end - def self.singleton_worker? + def self.scalable? maximum_workers_count.kind_of?(Integer) && maximum_workers_count == 1 end - def singleton_worker? - self.class.singleton_worker? + def scalable? + self.class.scalable? end def self.workers_configured_count diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 728b5cdae6a..927656016ef 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -17,7 +17,7 @@ def slice_base_name end def service_name - singleton_worker? ? service_base_name : "#{service_base_name}@" + scalable? ? service_base_name : "#{service_base_name}@" end def service_file_name @@ -125,7 +125,7 @@ def unit_name end def unit_instance - singleton_worker? ? "" : "@#{guid}" + scalable? ? "" : "@#{guid}" end def write_unit_settings_file From ffa108cebebd3901bb8a7d76feb1ea599b908e52 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 15 May 2019 15:45:07 -0400 Subject: [PATCH 46/49] Fix MiqWorker.scalable? logic --- app/models/miq_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index 55fe3c0eda1..c77c85c46c7 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -54,7 +54,7 @@ def self.workers end def self.scalable? - maximum_workers_count.kind_of?(Integer) && maximum_workers_count == 1 + maximum_workers_count.nil? || maximum_workers_count > 1 end def scalable? From 211103865477f08e19c3c174b41f89caeb6cb68b Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 15 May 2019 15:54:36 -0400 Subject: [PATCH 47/49] Use Rails.root for systemd working_directory --- app/models/miq_worker/systemd_common.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index 927656016ef..d3010798eeb 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -66,8 +66,7 @@ def unit_file end def working_directory - # TODO: pull this dynamically - "/var/www/miq/vmdb" + Rails.root end def exec_start From a0e15d602a4baca78581755c25cf1e0c0f90c621 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 20 May 2019 08:13:19 -0400 Subject: [PATCH 48/49] Catch LoadError on systemd-journal gem --- lib/vmdb/loggers.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index cdca91fbabc..a0b30006fd2 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -48,11 +48,7 @@ def self.create_loggers $audit_log = AuditLogger.new(path_dir.join("audit.log")) $container_log = ContainerLogger.new - if MiqEnvironment::Command.supports_systemd? - require "manageiq/loggers/journald" - $journald_log = ManageIQ::Loggers::Journald.new - end - + $journald_log = create_journald_logger $log = create_multicast_logger(path_dir.join("evm.log")) $rails_log = create_multicast_logger(path_dir.join("#{Rails.env}.log")) $api_log = create_multicast_logger(path_dir.join("api.log")) @@ -86,6 +82,15 @@ def self.create_multicast_logger(log_file_path, logger_class = VMDBLogger) end private_class_method :create_multicast_logger + private_class_method def self.create_journald_logger + return unless MiqEnvironment::Command.supports_systemd? + + require "manageiq/loggers/journald" + ManageIQ::Loggers::Journald.new + rescue LoadError + nil + end + def self.configure_external_loggers require 'awesome_spawn' AwesomeSpawn.logger = $log From 9ba6c3a5621ad49047fd85edce79b0021cde8584 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 20 May 2019 08:16:50 -0400 Subject: [PATCH 49/49] Move supports_systemd? to module and catch LoadError --- app/models/miq_worker.rb | 4 ---- app/models/miq_worker/systemd_common.rb | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index c77c85c46c7..869d3c60ae3 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -367,10 +367,6 @@ def containerized_worker? self.class.containerized_worker? end - def self.supports_systemd? - worker_settings[:systemd_enabled] - end - def self.systemd_worker? MiqEnvironment::Command.supports_systemd? && supports_systemd? end diff --git a/app/models/miq_worker/systemd_common.rb b/app/models/miq_worker/systemd_common.rb index d3010798eeb..ecca57f6d0c 100644 --- a/app/models/miq_worker/systemd_common.rb +++ b/app/models/miq_worker/systemd_common.rb @@ -3,6 +3,13 @@ module SystemdCommon extend ActiveSupport::Concern class_methods do + def supports_systemd? + return unless worker_settings[:systemd_enabled] + require "dbus/systemd" + rescue LoadError + false + end + def ensure_systemd_files target_file_path.write(target_file) unless target_file_path.exist? service_file_path.write(unit_file) unless service_file_path.exist?