Services - check ChkConfig and systemd UnitFiles

This combiner provides information about whether a given service is enabled, using parsers for chkconfig (for RHEL 5 and 6) and systemd list-unit-files (for RHEL 7 and above).

Examples

>>> svcs = shared[Services]
>>> svcs.is_on('atd') # Can be 'atd' or 'atd.service'.
True
>>> svcs.is_on('systemd-journald.service')
True
>>> 'atd' in svcs
True
>>> svcs.service_line('atd')
'atd.service                                 enabled'
>>> 'disabled_service' in svcs
False
>>> 'nonexistent_service' in svcs
False
class insights.combiners.services.Services(chk_config, unit_files)[source]

Bases: object

A combiner for working with enabled services, independent of which version of RHEL is in use.

The interface closely follows the models of ChkConfig and UnitFiles:

  • is_on(service_name) and the service_name in Services method return whether the service given is present and enabled.

  • service_line(service_name) returns the actual line that contained the service name.

is_on(service_name)[source]

Checks if the service is enabled on the system.

Parameters

service_name (str) -- service name (with or without ‘.service’ suffix).

Returns

True if service is enabled, False otherwise.

Return type

bool

service_line(service_name)[source]

Returns the relevant line from the service listing.

Parameters

service_name (str) -- service name (with or without ‘.service’ suffix).

Returns

True if service is enabled, False otherwise.

Return type

str