Resolve systemd alias (service name)
Asked Answered
G

1

9

Systemd supports aliases. For example "httpd.service"

ls -l /etc/systemd/system/httpd.service
  /etc/systemd/system/httpd.service -> /usr/lib/systemd/system/apache2.service

Content of this file:

[Unit]
Description=The Apache Webserver
...
[Install]
WantedBy=multi-user.target
Alias=httpd.service apache.service

I would like to resolve the alias in a script.

Example:

If the input is "httpd.service", then the output should be "apache2.service"

I can use shell or python for this script.

How to do this the systemd-way?

Reading the symlink might work, but I guess there is a more official way to resolve the alias.

Glottalized answered 4/2, 2019 at 11:41 Comment(0)
A
10

You should ask for the Id property of the aliased service

> systemctl show -p Id --value httpd.service
apache2.service

You can also query the Names property

> systemctl show -p Names --value httpd.service
httpd.service apache2.service
Addington answered 31/1, 2020 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.