Skip to content

Commit

Permalink
Merge pull request #20824 from agrare/dont_restart_systemd_worker_aut…
Browse files Browse the repository at this point in the history
…omatically

Auto-restart systemd workers results in duplicates
  • Loading branch information
jrafanie authored Nov 19, 2020
2 parents 0a56551 + d215045 commit 2f8ae23
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
22 changes: 22 additions & 0 deletions app/models/miq_server/at_startup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@ module MiqServer::AtStartup
include Vmdb::Logging

module ClassMethods
def startup!
log_managed_entities
write_systemd_unit_files
clean_all_workers
clean_dequeued_messages
purge_report_results
end

def log_managed_entities
region = MiqRegion.my_region
prefix = "#{_log.prefix} Region: [#{region.region}], name: [#{region.name}]"
log_under_management(prefix)
log_not_under_management(prefix)
end

def write_systemd_unit_files
return unless MiqEnvironment::Command.supports_systemd?

_log.info("Writing Systemd unit files...")
MiqWorkerType.worker_class_names.each do |class_name|
worker_klass = class_name.safe_constantize
worker_klass.ensure_systemd_files if worker_klass&.systemd_worker?
rescue => err
_log.warn("Failed to write systemd service files: #{err}")
_log.log_backtrace(err)
end
_log.info("Writing Systemd unit files...Complete")
end

# Delete and Kill all workers that were running previously
def clean_all_workers
_log.info("Cleaning up all workers...")
Expand Down
1 change: 0 additions & 1 deletion app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def sync_workers
c = class_name.constantize
raise NameError, "Constant problem: expected: #{class_name}, constantized: #{c.name}" unless c.name == class_name

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
Expand Down
6 changes: 3 additions & 3 deletions app/models/miq_worker/systemd_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def supports_systemd?
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?
target_file_path.write(target_file)
service_file_path.write(unit_file)
end

def service_base_name
Expand Down Expand Up @@ -69,7 +69,7 @@ def unit_file
WorkingDirectory=#{working_directory}
Environment=BUNDLER_GROUPS=#{bundler_groups.join(",")}
ExecStart=/bin/bash -lc '#{exec_start}'
Restart=always
Restart=no
Slice=#{slice_name}
UNIT_FILE
end
Expand Down
5 changes: 1 addition & 4 deletions lib/workers/evm_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ def start_server
configure_server_roles
clear_queue

MiqServer.log_managed_entities
MiqServer.clean_all_workers
MiqServer.clean_dequeued_messages
MiqServer.purge_report_results
MiqServer.startup!

@current_server.delete_active_log_collections_queue

Expand Down

0 comments on commit 2f8ae23

Please sign in to comment.