Skip to content

Commit

Permalink
Write systemd service files on startup not in sync_workers
Browse files Browse the repository at this point in the history
When the systemd worker option was first introduced as a prototype there
was a setting that would control if systemd or the normal forking worker
mode was used.  This setting was per worker, and was done in
sync_workers so that you could change the setting "on-the-fly" without
restarting the entire evmserverd process.  This made it much easier to
try out using systemd on one or two workers very quickly.

Now that systemd is the default for appliances the ability to change
this dynamically isn't very helpful, and writing out systemd unit files
during sync_workers is just a lot of overhead.

Moving the writing of systemd unit files to miq_server startup removes
the overhead per-sync_workers-loop and allows us to update the contents
of the files without checking .exist? (which was done due to the
frequency with which it was being run).
  • Loading branch information
agrare committed Nov 19, 2020
1 parent ccd6a06 commit f7d11bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/models/miq_server/at_startup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module MiqServer::AtStartup
module ClassMethods
def startup!
log_managed_entities
write_systemd_service_files if MiqEnvironment::Command.supports_systemd?
clean_all_workers
clean_dequeued_messages
purge_report_results
Expand All @@ -17,6 +18,16 @@ def log_managed_entities
log_not_under_management(prefix)
end

def write_systemd_service_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
end

# Delete and Kill all workers that were running previously
def clean_all_workers
_log.info("Cleaning up all workers...")
Expand Down
4 changes: 2 additions & 2 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

0 comments on commit f7d11bb

Please sign in to comment.