Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolve systemd alias (service name)

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.

like image 259
guettli Avatar asked Apr 26 '26 07:04

guettli


1 Answers

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
like image 187
Cyrille Pontvieux Avatar answered Apr 27 '26 22:04

Cyrille Pontvieux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!