Skip to content

Disabled units #1

@ratatosk85

Description

@ratatosk85

Hello, thanks for the script, but there is a problem:
if the unit is disabled, then it is not displayed in the systemctl list-units list. I modified a little for myself - added one more loop before the main one:

lines = subprocess.check_output(["/bin/systemctl", "list-units", "-a", "-t", "service", "--no-legend"]).decode("UTF-8").split("\n")
lines_disabled = subprocess.check_output(["/bin/systemctl", "list-unit-files", "-a", "-t", "service", "--no-legend"]).decode("UTF-8").split("\n")
        for line in lines_disabled:
            if line and not "@." in line:
               result = re.search(r"^(.+)\.service\s+(\w+).*$", line)
               service_name = result.group(1)
               service_mode = result.group(2)
               if service_mode == 'disabled':
                    service_mode = 3
                    service_oid = self.create_oid(service_name)
                    self.data[service_oid] = ('integer', service_mode, service_name)
                    oids.append(service_oid)

        for line in lines:
            if line and not "@." in line:
            ...

I think a good programmer will make it more beautiful

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions