Units Manged By Systemctl (services)¶
Parsers included in this module are:
ListUnits - command /bin/systemctl list-units
¶
UnitFiles - command /bin/systemctl list-unit-files
¶
-
class
insights.parsers.systemd.unitfiles.
ListUnits
(*args, **kwargs)[source]¶ Bases:
insights.core.Parser
The ListUnits class parses the output of
/bin/systemctl list-units
and provides information about all the services listed under it.Output of Command:
UNIT LOAD ACTIVE SUB DESCRIPTION sockets.target loaded active active Sockets swap.target loaded active active Swap systemd-shutdownd.socket loaded active listening Delayed Shutdown Socket neutron-dhcp-agent.service loaded active running OpenStack Neutron DHCP Agent neutron-openvswitch-agent.service loaded active running OpenStack Neutron Open vSwitch Agent ... unbound-anchor.timer loaded active waiting daily update of the root trust anchor for DNSSEC LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 161 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
Raises: SkipComponent
-- When nothing is parsed.Example
>>> units.get_service_details('swap.target') == {'LOAD': 'loaded', 'ACTIVE': 'active', 'SUB': 'active', 'UNIT': 'swap.target', 'DESCRIPTION': 'Swap'} True >>> units.unit_list['swap.target'] == {'LOAD': 'loaded', 'ACTIVE': 'active', 'SUB': 'active', 'UNIT': 'swap.target', 'DESCRIPTION': 'Swap'} True >>> units.is_active('swap.target') True >>> units.get_service_details('random.service') == {'LOAD': None, 'ACTIVE': None, 'SUB': None, 'UNIT': None, 'DESCRIPTION': None} True
-
get_service_details
(service_name)[source]¶ Return the service details collected by systemctl.
Parameters: service_name (str) -- service name including its extension. Returns: Dictionary containing details for the service. if service is not present dictonary values will be None: {'LOAD': 'loaded', 'ACTIVE': 'active', 'SUB': 'running', 'UNIT': 'neutron-dhcp-agent.service'}
Return type: dict
-
is_active
(service_name)[source]¶ Return the ACTIVE state of service managed by systemd.
Parameters: service_name (str) -- service name including its extension. Returns: True if service is active False if inactive Return type: bool
-
is_failed
(service_name)[source]¶ Return the ACTIVE state of service managed by systemd.
Parameters: service_name (str) -- service name including its extension. Returns: True if service is failed, False in all other states. Return type: bool
-
is_loaded
(service_name)[source]¶ Return the LOAD state of service managed by systemd.
Parameters: service_name (str) -- service name including its extension. Returns: True if service is loaded False if not loaded Return type: bool
-
is_running
(service_name)[source]¶ Return the SUB state of service managed by systemd.
Parameters: service_name (str) -- service name including its extension. Returns: True if service is running False in all other states. Return type: bool
-
parse_content
(content)[source]¶ Main parsing class method which stores all interesting data from the content.
Parameters: content (context.content) -- Parser context content
-
service_names
¶ Returns a list of all UNIT names.
Type: list
-
unit_list
= None¶ Dictionary service detail like active, running, exited, dead
Type: dict
-
-
class
insights.parsers.systemd.unitfiles.
UnitFiles
(*args, **kwargs)[source]¶ Bases:
insights.core.Parser
The UnitFiles class parses the output of
/bin/systemctl list-unit-files
and provides information about enabled services.- Output of Command::
- UNIT FILE STATE mariadb.service enabled neutron-openvswitch-agent.service enabled neutron-ovs-cleanup.service enabled neutron-server.service enabled runlevel0.target disabled runlevel1.target disabled runlevel2.target enabled
Raises: SkipComponent
-- When nothing is parsed.Example
>>> conf.is_on('mariadb.service') True >>> conf.is_on('runlevel0.target') False >>> conf.exists('neutron-server.service') True >>> conf.exists('runlevel1.target') True >>> 'mariadb.service' in conf.services True >>> 'runlevel0.target' in conf.services True >>> 'nonexistent-service.service' in conf.services False >>> conf.services['mariadb.service'] True >>> conf.services['runlevel1.target'] False >>> conf.services['nonexistent-service.service'] Traceback (most recent call last): File "<doctest insights.parsers.systemd.unitfiles.UnitFiles[11]>", line 1, in <module> conf.services['nonexistent-service.service'] KeyError: 'nonexistent-service.service'
-
exists
(service_name)[source]¶ Checks if the service is listed in systemctl.
Parameters: service_name (str) -- service name including ‘.service’ Returns: True if service exists, False otherwise. Return type: bool
-
is_on
(service_name)[source]¶ Checks if the service is enabled in systemctl.
Parameters: service_name (str) -- service name including ‘.service’ Returns: True if service is enabled, False if it is disabled. None if the service doesn’t exist. Return type: Union[bool, None]
-
parse_content
(content)[source]¶ Main parsing class method which stores all interesting data from the content.
Parameters: content (context.content) -- Parser context content
-
parsed_lines
= None¶ Dictionary of content lines access by service name.
Type: dict
-
service_list
= None¶ List of service names in order of appearance.
Type: list
-
services
= None¶ Dictionary of bool indicating if service is enabled, access by service name .
Type: dict