eclipse-bluechi / bluechi

Eclipse BlueChi is a systemd service controller intended for multi-node environments with a predefined number of nodes and with a focus on highly regulated ecosystems such as those requiring functional safety.
https://bluechi.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
130 stars 37 forks source link

ListUnits method doesn't get unit of service generated by quadlet #887

Closed dofmind closed 4 months ago

dofmind commented 4 months ago

The ListUnits method does not get the unit of service generated by quadlet when the service is inactive, even if the service is loaded.

The sample-app-a and the sample-app-b are generated by quadlet using below files

After running only sample-app-a, bluechictl list-units command doesn't get information of sample-app-b.

root@hpc-base:~# bluechictl list-units hpc-ad | grep sample
hpc-ad              |sample-app-a.service                                       |   active|  running
root@hpc-base:~#

The sample-app-b is inactive but it is loaded.

root@hpc-ad:~# systemctl status sample-app-a
● sample-app-a.service - The sample application container
     Loaded: loaded (/etc/containers/systemd/sample-app-a.container; generated)
     Active: active (running) since Thu 2024-04-18 13:34:46 KST; 3h 11min ago
...
root@hpc-ad:~#
root@hpc-ad:~# systemctl status sample-app-b
○ sample-app-b.service - The sample application container
     Loaded: loaded (/etc/containers/systemd/sample-app-b.container; generated)
     Active: inactive (dead)
root@hpc-ad:~#

systemdctl list-units --all also has same result.

root@hpc-ad:~# systemctl list-units --all | grep sample
  sample-app-a.service               loaded    active     running         The sample application container
root@hpc-ad:~# 

Does anyone know why I can't get the unit of service generated by the quadlet?

engelmi commented 4 months ago

Hi @dofmind,

Good question. According to systemctl man page:

List units that systemd currently has in memory. This includes units that are either referenced directly or through a dependency, units that are pinned by applications programmatically, or units that were active in the past and have failed. By default only units which are active, have pending jobs, or have failed are shown; this can be changed with option --all.

If I understand this correctly, the Loaded: loaded state isn't enough for a unit to be listed by systemctl list-units (with and without the --all flag). For a unit to be listed there it needs to

So if you add to /etc/containers/systemd/sample-app-b.container:

...
[Install]
WantedBy=multi-user.target

Then it should get listed by bluechictl | systemctl list-units --all:

$ systemctl daemon-reload

# shouldn't show anything since sample-app-b.service is inactive
$ systemctl list-units | grep sample

# --all needed
$ systemctl list-units --all | grep sample
sample-app-a.service               loaded    active     running         The sample application container
sample-app-b.service               loaded    inactive   dead            The sample application container

NOTE: Since sample-app-b.container generates sample-app-b.service it is not possible to enable it:

$ systemctl enable sample-app-b.service
Failed to enable unit: Unit /run/systemd/generator/sample-app-b.service is transient or generated.

But creating such an artificial dependency just so it get the unit listed by list-units is a bit pointless. The command systemctl list-unit-files (see list-unit-files man page) is probably better suited to get an overview of available units (and services). We currently don't have a ListUnitFiles API in BlueChi, though. I think it would make sense to add it. What do you think? @mkemel @mwperina

dofmind commented 4 months ago

Ah, my question has been resolved. Thank you for your reply. If BlueChi has a ListUnitFiles API, it will be useful when the state-manager checks whether a unit is serviceable on the node.

mwperina commented 4 months ago

The command systemctl list-unit-files (see list-unit-files man page) is probably better suited to get an overview of available units (and services). We currently don't have a ListUnitFiles API in BlueChi, though. I think it would make sense to add it. What do you think? @mkemel @mwperina

Yeah, let's change this ticket to RFE to add ListUnitFiles functionality

engelmi commented 4 months ago

I created a new RFE issue (https://github.com/eclipse-bluechi/bluechi/issues/889) for a better overview. Please have a look at it @dofmind and comment if we should add/change something.

Closing this issue.