0

I'm trying to determine whether a process is running successfully for a service that's scheduled as a systemd-timers service. I have a service scheduled called certbot.service, which I can see using systemctl list-timers. Where is the definition for that service, and how can I determine the process that will ultimately be triggered for that service?

1 Answer 1

1

When you use systemctl list-timers you are listing the active *.timer units.

Example:

stew ~ $ systemctl list-timers
NEXT                         LEFT          LAST                         PASSED       UNIT                         ACTIVATES
Wed 2021-09-08 10:32:20 CEST 46min left    Wed 2021-09-08 09:32:47 CEST 13min ago    anacron.timer                anacron.service
Wed 2021-09-08 10:58:47 CEST 1h 12min left Wed 2021-09-08 04:35:18 CEST 5h 10min ago apt-daily.timer              apt-daily.service
Wed 2021-09-08 13:28:09 CEST 3h 41min left Tue 2021-09-07 13:28:09 CEST 20h ago      systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Wed 2021-09-08 15:40:34 CEST 5h 54min left Wed 2021-09-08 05:01:01 CEST 4h 45min ago fwupd-refresh.timer          fwupd-refresh.service
Thu 2021-09-09 00:00:00 CEST 14h left      Wed 2021-09-08 00:00:01 CEST 9h ago       atop-rotate.timer            atop-rotate.service
Thu 2021-09-09 00:00:00 CEST 14h left      Wed 2021-09-08 00:00:01 CEST 9h ago       exim4-base.timer             exim4-base.service
Thu 2021-09-09 00:00:00 CEST 14h left      Wed 2021-09-08 00:00:01 CEST 9h ago       logrotate.timer              logrotate.service
Thu 2021-09-09 00:00:00 CEST 14h left      Wed 2021-09-08 00:00:01 CEST 9h ago       man-db.timer                 man-db.service
Thu 2021-09-09 06:20:05 CEST 20h left      Wed 2021-09-08 06:01:22 CEST 3h 44min ago apt-daily-upgrade.timer      apt-daily-upgrade.service
Sun 2021-09-12 03:10:53 CEST 3 days left   Sun 2021-09-05 03:10:52 CEST 3 days ago   e2scrub_all.timer            e2scrub_all.service

10 timers listed.
Pass --all to see loaded but inactive timers, too.

You can see that in the UNIT column we have timer units (e.g. anacron.timer) This is the actual timer that you are listing. When that timer triggers, it will activate another unit. That unit can be specified in the *.timer file as Unit=anacron.service or defaults to a service with the same name as the timer, but with a .service extension. The ACTIVATES column shows you this.

If you want to know where the *.timer is set, use systemctl cat <unit>:

stew ~ $ systemctl cat anacron.timer
# /lib/systemd/system/anacron.timer
[Unit]
Description=Trigger anacron every hour

[Timer]
OnCalendar=*-*-* 07..23:30
RandomizedDelaySec=5m
Persistent=true

[Install]
WantedBy=timers.target

What's especially useful here is that it tells you the name of the file(s). If you have any drop-ins, they will be listed.

In your case, you are specifically interested in the process that is triggered by your service. systemctl cat <unit> can help you there too. If I continue with the anacron.service you get:

stew ~ $ systemctl cat anacron.service
# /lib/systemd/system/anacron.service
...

[Service]
EnvironmentFile=/etc/default/anacron
ExecStart=/usr/sbin/anacron -d -q $ANACRON_ARGS
...

You can see the ExecStart= line shows the command that is run to start the service.

If you're interested in the current status, you can also see that with systemctl status <unit>:

stew ~ $ systemctl status anacron.service
● anacron.service - Run anacron jobs
...
     Active: inactive (dead) since Wed 2021-09-08 09:32:47 CEST; 23min ago
TriggeredBy: ● anacron.timer
    Process: 480643 ExecStart=/usr/sbin/anacron -d -q $ANACRON_ARGS (code=exited, status=0/SUCCESS)
   Main PID: 480643 (code=exited, status=0/SUCCESS)
...

Her you can see when the service last completed, the ExecStart= command used, the PID, and the exit code.

1
  • One of the best answers I've seen - thanks @Stewart ;) Sep 10, 2021 at 4:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .