aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sos/plugins/__init__.py6
-rw-r--r--sos/policies/__init__.py22
2 files changed, 23 insertions, 5 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 47b028a8..030e7a30 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -215,9 +215,13 @@ class Plugin(object):
'''Is the service $name disabled?'''
return self.policy.init_system.is_disabled(name)
+ def service_is_running(self, name):
+ '''Is the service $name currently running?'''
+ return self.policy.init_system.is_running(name)
+
def get_service_status(self, name):
'''Return the reported status for service $name'''
- return self.policy.init_system.get_service_status(name)
+ return self.policy.init_system.get_service_status(name)['status']
def do_cmd_private_sub(self, cmd):
'''Remove certificate and key output archived by sosreport. cmd
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index d6255d3e..d0b18015 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -86,6 +86,17 @@ class InitSystem(object):
"""
return name in self.services
+ def is_running(self, name):
+ """Checks if the given service name is in a running state.
+
+ This should be overridden by initsystems that subclass InitSystem
+ """
+ # This is going to be primarily used in gating if service related
+ # commands are going to be run or not. Default to always returning
+ # True when an actual init system is not specified by policy so that
+ # we don't inadvertantly restrict sosreports on those systems
+ return True
+
def load_all_services(self):
"""This loads all services known to the init system into a dict.
The dict should be keyed by the service name, and contain a dict of the
@@ -96,10 +107,9 @@ class InitSystem(object):
def _query_service(self, name):
"""Query an individual service"""
if self.query_cmd:
- res = sos_get_command_output("%s %s" % (self.query_cmd, name))
- if res['status'] == 0:
- return res
- else:
+ try:
+ return sos_get_command_output("%s %s" % (self.query_cmd, name))
+ except Exception:
return None
return None
@@ -156,6 +166,10 @@ class SystemdInit(InitSystem):
except IndexError:
pass
+ def is_running(self, name):
+ svc = self.get_service_status(name)
+ return svc['status'] == 'active'
+
class PackageManager(object):
"""Encapsulates a package manager. If you provide a query_command to the