138

There are many different places where systemd unit files may be placed. Is there a quick and easy way to ask systemd where it read a service’s declaration from, given just the service name?

Chris Stryczynski
  • 1,176
  • 2
  • 15
  • 23
Joachim Breitner
  • 3,469
  • 3
  • 17
  • 20

2 Answers2

149

For units that are defined in actual, static files, this can be seen in systemctl status:

$ systemctl status halt-local.service
● halt-local.service - /usr/sbin/halt.local Compatibility
   Loaded: loaded (/lib/systemd/system/halt-local.service; static)
   Active: inactive (dead)

But there are units that are not defined by files, e.g. with systemd-cron installed. These have no useful location listed with status:

$ systemctl status cron-jojo-0.timer
● cron-jojo-0.timer - [Cron] "*/10 * * * * ..."
   Loaded: loaded (/var/spool/cron/crontabs/jojo)
   Active: active (waiting) since Mon 2015-05-18 14:53:01 UTC; 9min ago

In either case, though, the FragmentPath field is educating:

$ systemctl show -P FragmentPath cron-daily.service
/lib/systemd/system/cron-daily.service
$ systemctl show -P FragmentPath cron-jojo-0.service
/run/systemd/generator/cron-jojo-0.service
$ systemctl show -P FragmentPath halt-local.service
/lib/systemd/system/halt-local.service
Joachim Breitner
  • 3,469
  • 3
  • 17
  • 20
  • How about the path of some mask service? (not all of them are in /lib/systemd/system or /usr/lib/systemd/system) – desgua Oct 31 '20 at 15:28
  • Good, but partial, answer. But FragmentPath can be empty, e.g: systemctl show -p FragmentPath subsystem-net-devices-eth0.device – BobHy Mar 31 '22 at 19:09
6

You could cat the systemd unit. This shows the file location as comments. Bonus: It also shows overrides.

systemctl cat sssd
# /lib/systemd/system/sssd.service
[Unit]
...

# /etc/systemd/system/sssd.service.d/override.conf
[Unit]
...
gmoktop
  • 71
  • 1
  • 1