Skip to content

Commit

Permalink
Use the systemd services instead of miq_workers table
Browse files Browse the repository at this point in the history
For the purposes of starting and stopping workers only looking at the
miq_workers table for the "current" list ignores the fact that there
might be existing services out there already created that are starting,
stopping, or failed and don't have a record tracking them in the
miq_workers table.
  • Loading branch information
agrare committed Aug 5, 2020
1 parent 85037e1 commit c8abf5a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/models/miq_server/worker_management/monitor/quiesce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ def quiesce_workers_loop
miq_workers.each do |w|
if w.containerized_worker?
w.delete_container_objects
elsif w.systemd_worker?
w.stop_systemd_worker
else
stop_worker(w)
end
Expand Down
15 changes: 14 additions & 1 deletion app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,20 @@ def self.enough_resource_to_start_worker?
MiqServer.my_server.enough_resource_to_start_worker?(self)
end

def self.cleanup_failed_workers
if containerized_worker?
elsif systemd_worker?
failed_services.each do |service|
cleanup_systemd_worker(service)
end
end
end

def self.sync_workers
cleanup_failed_workers

w = include_stopping_workers_on_synchronize ? find_alive : find_current_or_starting
current = w.length
current = systemd_worker? ? active_services : w.length
desired = workers
result = {:adds => [], :deletes => []}

Expand All @@ -143,6 +154,8 @@ def self.sync_workers
w = w.to_a
(current - desired).times do
ww = w.pop
# TODO add interface to get worker instance by service name
ww = find_by(:guid => ww.split("@"))
result[:deletes] << ww.pid
ww.stop
end
Expand Down
29 changes: 25 additions & 4 deletions app/models/miq_worker/systemd_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ def supports_systemd?
false
end

def systemd_manager
@systemd_manager ||= begin
require "dbus/systemd"
DBus::Systemd::Manager.new
end
end

def services
systemd_manager.units.select { |unit| unit[:name].start_with?(service_name) }
end

def active_services
services.select { |service| service[:active_state] == "active" }.map { |service| service[:name] }
end

def failed_services
services.select { |service| service[:active_state] == "failed" }.map { |service| service[:name] }
end

def cleanup_systemd_worker(unit_name, runtime: false)
# TODO cleanup unit settings
systemd_manager.DisableUnitFiles([unit_name], runtime)
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?
Expand Down Expand Up @@ -118,10 +142,7 @@ def stop_systemd_unit(mode: "replace")
private

def systemd
@systemd ||= begin
require "dbus/systemd"
DBus::Systemd::Manager.new
end
self.class.systemd_manager
end

def service_base_name
Expand Down

0 comments on commit c8abf5a

Please sign in to comment.