-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup failed systemd services during sync_workers
It is possible for a systemd or container deployment to fail and no longer be run (e.g. CrashLoopBackOff) but the deployment/service will still exist in the runtime environment. Add the ability for these failed services to be cleaned up during MiqServer's sync_workers loop.
- Loading branch information
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/models/miq_server/worker_management/monitor/systemd.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module MiqServer::WorkerManagement::Monitor::Systemd | ||
extend ActiveSupport::Concern | ||
|
||
def systemd_manager | ||
@systemd_manager ||= begin | ||
require "dbus/systemd" | ||
DBus::Systemd::Manager.new | ||
end | ||
end | ||
|
||
def cleaup_failed_systemd_services | ||
failed_service_names = systemd_failed_miq_services.map { |service| service[:name] } | ||
systemd_manager.DisableUnitFiles(failed_service_names, false) | ||
end | ||
|
||
def systemd_miq_service_base_names | ||
@systemd_miq_service_base_names ||= begin | ||
MiqWorkerType.worker_class_names.map(&:constantize).map(&:service_base_name) | ||
end | ||
end | ||
|
||
def systemd_failed_miq_services | ||
miq_services(systemd_failed_services) | ||
end | ||
|
||
def systemd_all_miq_services | ||
miq_services(systemd_services) | ||
end | ||
|
||
def miq_services(services) | ||
services.select { |unit| systemd_miq_service_base_names.include?(systemd_service_base_name(unit)) } | ||
end | ||
|
||
def systemd_service_name(unit) | ||
File.basename(unit[:name], ".*") | ||
end | ||
|
||
def systemd_service_base_name(unit) | ||
systemd_service_name(unit).split("@").first | ||
end | ||
|
||
def systemd_failed_services | ||
systemd_services.select { |service| service[:active_state] == "failed" } | ||
end | ||
|
||
def systemd_services | ||
systemd_units.select { |unit| File.extname(unit[:name]) == ".service" } | ||
end | ||
|
||
def systemd_units | ||
systemd_manager.units | ||
end | ||
end |