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.
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