Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't dynamically write systemd unit files #21120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions app/models/miq_server/at_startup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module MiqServer::AtStartup
module ClassMethods
def startup!
log_managed_entities
write_systemd_unit_files
clean_all_workers
clean_dequeued_messages
purge_report_results
Expand All @@ -18,20 +17,6 @@ def log_managed_entities
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
2 changes: 1 addition & 1 deletion app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def containerized_worker?
end

def self.systemd_worker?
MiqEnvironment::Command.supports_systemd? && supports_systemd?
MiqEnvironment::Command.supports_systemd?
end

def systemd_worker?
Expand Down
78 changes: 1 addition & 77 deletions app/models/miq_worker/systemd_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,12 @@ module SystemdCommon
extend ActiveSupport::Concern

class_methods do
def supports_systemd?
return unless worker_settings[:systemd_enabled]
require "dbus/systemd"
true
rescue LoadError
false
end

def ensure_systemd_files
target_file_path.write(target_file)
service_file_path.write(unit_file)
end

def service_base_name
minimal_class_name.underscore.tr("/", "_")
end

def slice_base_name
"miq"
end

def service_name
"#{service_base_name}@"
end

def service_file_name
"#{service_name}.service"
end

def slice_name
"#{slice_base_name}-#{service_base_name}.slice"
end

def service_file_path
systemd_unit_dir.join(service_file_name)
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("/etc/systemd/system")
end

def target_file
<<~TARGET_FILE
[Unit]
PartOf=miq.target
TARGET_FILE
end

def unit_file
<<~UNIT_FILE
[Unit]
PartOf=#{target_file_name}
[Install]
WantedBy=#{target_file_name}
[Service]
WorkingDirectory=#{working_directory}
Environment=BUNDLER_GROUPS=#{bundler_groups.join(",")}
ExecStart=/bin/bash -lc '#{exec_start}'
Restart=no
Type=notify
Slice=#{slice_name}
UNIT_FILE
end

def working_directory
Rails.root
end

def exec_start
"exec ruby lib/workers/bin/run_single_worker.rb #{name} #{run_single_worker_args}"
end

def run_single_worker_args
"--heartbeat --guid=%i"
Pathname.new("/lib/systemd/system")
end
end

Expand Down
1 change: 0 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@
:poll_method: normal
:starting_timeout: 10.minutes
:stopping_timeout: 10.minutes
:systemd_enabled: true
:event_catcher:
:defaults:
:flooding_events_per_minute: 30
Expand Down