Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dofmind opened this issue Apr 18, 2024 · 4 comments
Closed

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

dofmind opened this issue Apr 18, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dofmind
Copy link
Contributor

dofmind commented Apr 18, 2024

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

  • /etc/containers/systemd/sample-app-a.container
  • /etc/containers/systemd/sample-app-b.container

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?

@dofmind dofmind added the bug Something isn't working label Apr 18, 2024
@engelmi
Copy link
Member

engelmi commented Apr 18, 2024

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

  • referenced directly, e.g. started and be in an active or failed state
  • referenced through a dependency, e.g. contains an [Install] section and is referenced by another unit that is part of the default dependency tree (so using multi-user.target should do the trick)

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
Copy link
Contributor Author

dofmind commented Apr 18, 2024

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
Copy link
Member

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 engelmi mentioned this issue Apr 22, 2024
6 tasks
@engelmi
Copy link
Member

engelmi commented Apr 22, 2024

I created a new RFE issue (#889) for a better overview.
Please have a look at it @dofmind and comment if we should add/change something.

Closing this issue.

@engelmi engelmi closed this as completed Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants