Skip to content

Commit

Permalink
Set system_uid in miq_server
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jul 25, 2024
1 parent ccfb65d commit d33aeb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
12 changes: 4 additions & 8 deletions app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class MiqWorker < ApplicationRecord
include SystemdCommon
include UuidMixin

after_initialize :set_system_uid
before_destroy :error_out_tasks_with_active_queue_message, :log_destroy_of_worker_messages

belongs_to :miq_server
Expand Down Expand Up @@ -338,7 +337,7 @@ def systemd_worker?
self.class.systemd_worker?
end

def start_runner
def start_runner!
if systemd_worker?
start_systemd_worker
elsif containerized_worker?
Expand Down Expand Up @@ -383,12 +382,13 @@ def start_runner_via_spawn
[:out, :err] => [Rails.root.join("log/evm.log"), "a"]
)
Process.detach(pid)
self.system_uid = self.pid = pid
pid
end

def start
self.pid = start_runner
save if !containerized_worker? && !systemd_worker?
start_runner!
save!

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)
Expand Down Expand Up @@ -494,10 +494,6 @@ def clean_active_messages
end
end

private def set_system_uid
self.system_uid = unit_name if systemd_worker?
end

private def error_out_tasks_with_active_queue_message
message = "Task Handler: [#{friendly_name}] ID [#{id}] has been deleted!"
processed_messages.includes(:miq_task).where.not(:miq_task_id => nil).each do |m|
Expand Down
13 changes: 10 additions & 3 deletions app/models/miq_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ def log_prefix
#

def find_worker_record
@worker = self.class.corresponding_model.find_by(:guid => @cfg[:guid])
do_exit("Unable to find instance for worker GUID [#{@cfg[:guid]}].", 1) if @worker.nil?
MiqWorker.my_guid = @cfg[:guid]
worker_find_opts = {}
if @cfg[:system_uid]
worker_find_opts[:system_uid] = @cfg[:system_uid]
else
worker_find_opts[:guid] = @cfg[:guid]
end

@worker = self.class.corresponding_model.find_by(worker_find_opts)
do_exit("Unable to find instance for worker [#{worker_find_opts.values.first}].", 1) if @worker.nil?
MiqWorker.my_guid = @worker.guid
end

def starting_worker_record
Expand Down
1 change: 1 addition & 0 deletions app/models/miq_worker/systemd_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def unit_name
end

def start_systemd_worker
self.system_uid = unit_name
enable_systemd_unit
write_unit_settings_file
start_systemd_unit
Expand Down

0 comments on commit d33aeb0

Please sign in to comment.