-
Notifications
You must be signed in to change notification settings - Fork 900
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
Track and kill embedded ansible monitoring thread #15612
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,12 @@ class EmbeddedAnsibleWorker < MiqWorker | |
self.required_roles = ['embedded_ansible'] | ||
|
||
def start_runner | ||
Thread.new do | ||
start_monitor_thread | ||
nil # return no pid | ||
end | ||
|
||
def start_monitor_thread | ||
t = Thread.new do | ||
begin | ||
self.class::Runner.start_worker(worker_options) | ||
# TODO: return supervisord pid | ||
|
@@ -17,13 +22,35 @@ def start_runner | |
Thread.exit | ||
end | ||
end | ||
nil # return no pid | ||
|
||
t[:worker_class] = self.class.name | ||
t[:worker_id] = id | ||
t | ||
end | ||
|
||
def kill | ||
stop | ||
thread = find_worker_thread_object | ||
|
||
if thread == Thread.main | ||
_log.warn("Cowardly refusing to kill the main thread.") | ||
elsif thread.nil? | ||
_log.info("The monitor thread for worker id: #{id} was not found, it must have already exited.") | ||
else | ||
_log.info("Exiting monitor thread...") | ||
thread.exit | ||
end | ||
destroy | ||
end | ||
|
||
def find_worker_thread_object | ||
Thread.list.detect do |t| | ||
t[:worker_id] == id && t[:worker_class] == self.class.name | ||
end | ||
end | ||
|
||
alias terminate kill | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the only other workers that implement |
||
alias stop kill | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want this? I think this worker still should be able to exit cleanly with stop if it is heartbeating, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right but I need to do some testing. |
||
|
||
def status_update | ||
# don't monitor the memory/cpu usage of this process yet | ||
# If we don't have a pid of a process we want to monitor,super will catch an Errno::ESRCH and abort the worker | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,6 @@ def find_worker_record | |
|
||
def starting_worker_record | ||
find_worker_record | ||
@worker.pid = Process.pid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We still need to let the worker set the pid when we call We need to remove most places making assumptions about calling Process.pid for the workers. |
||
@worker.status = "starting" | ||
@worker.started_on = Time.now.utc | ||
@worker.last_heartbeat = Time.now.utc | ||
|
@@ -190,7 +189,7 @@ def started_worker_record | |
@worker.last_heartbeat = Time.now.utc | ||
@worker.update_spid | ||
@worker.save | ||
$log.info("#{self.class.name} started. ID [#{@worker.id}], PID [#{Process.pid}], GUID [#{@worker.guid}], Zone [#{MiqServer.my_zone}], Role [#{MiqServer.my_role}]") | ||
$log.info("#{self.class.name} started. ID [#{@worker.id}], PID [#{@worker.pid}], GUID [#{@worker.guid}], Zone [#{MiqServer.my_zone}], Role [#{MiqServer.my_role}]") | ||
end | ||
|
||
def reload_worker_record | ||
|
@@ -293,7 +292,7 @@ def sync_config | |
sync_log_level | ||
sync_worker_settings | ||
sync_blacklisted_events | ||
_log.info("ID [#{@worker.id}], PID [#{Process.pid}], GUID [#{@worker.guid}], Zone [#{@my_zone}], Active Roles [#{@active_roles.join(',')}], Assigned Roles [#{MiqServer.my_role}], Configuration:") | ||
_log.info("ID [#{@worker.id}], PID [#{@worker.pid}], GUID [#{@worker.guid}], Zone [#{@my_zone}], Active Roles [#{@active_roles.join(',')}], Assigned Roles [#{MiqServer.my_role}], Configuration:") | ||
$log.log_hashes(@worker_settings) | ||
$log.info("---") | ||
$log.log_hashes(@cfg) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're setting thread instance variables in the Thread object so we can locate the thread for this worker later.