01 May 2018

Aliasing a SystemD Unit

Topics: Configuration Management, Linux
Tags: systemd

I recently encountered a situation where different versions of a debian package were creating different service names for SystemD, wreaking havoc with deployment and management scripts.

Fortunately SystemD has nice support for aliasing its services. Of course the documentation could be better; fortunately someone else discovered and wrote about this and the duck found the clues.

While there is an alias directive you can use within a unit file, SystemD supports symlinking an alias to a file in the directory containing the units.

To find the name of the unit file: systemctl list-unit-files

Then find the unit file that was loaded by looking for the line Loaded: in the output of systemctl status _unit_file_name_

Then just create a symbolic link to whatever name you would like to use and execute systemctl daemon-reload. systemctl status will show identical out for both your alias and the real unit name, and any systemctl or service commands may be directed at either name.