2

I'm trying to run a systemd timer every minute as a user, but it isn't repeating after the initial trigger. The ffmpeg-timelapse.timer is configured with the OnCalendar=minutely to fire every minute, and the ffmpeg-timelapse.target is WantedBy the dependent services. This allows me to easily add/remove cameras from the timelapse configuration.

The issue I am encountering is when I start the ffmpeg-timelapse.timer unit it will schedule for the next minute, but it will not repeat. The same issue occurs if I start it with the --now argument.

ffmpeg-timelapse.timer

[Unit]
Description=Runs ffmpeg timelapse units every minute

[Timer]
OnCalendar=minutely
Unit=ffmpeg-timelapse.target

[Install]
WantedBy=timers.target

ffmpeg-timelapse.target

[Unit]
Description=Triggers the individual timelapse units for each camera.
StopWhenUnneeded=yes

An example of the service file for a camera.

ffmpeg-timelapse01-front-yard.service

[Unit]
Description=Front Yard Timelapse Unit
Wants=ffmpeg-timelapse.timer

[Service]
ExecStart=/bin/bash -ac '. camera01.conf ; exec ffmpeg-timelapse.sh'

[Install]
WantedBy=ffmpeg-timelapse.target

Enabling and starting the service schedules it for the next minute.

$ systemctl --user start ffmpeg-timelapse.timer 
$ systemctl --user list-timers 
NEXT                         LEFT     LAST PASSED UNIT                   ACTIVATES
Sat 2020-06-06 12:08:00 EDT  12s left n/a  n/a    ffmpeg-timelapse.timer ffmpeg-timelapse.target

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

However once it runs it does not fire a second time.

$ systemctl --user list-timers 
NEXT LEFT LAST                         PASSED      UNIT                   ACTIVATES
n/a  n/a  Sat 2020-06-06 12:08:42 EDT  1min 2s ago ffmpeg-timelapse.timer ffmpeg-timelapse.target

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

The user I am running this as has linger enabled.

$ loginctl show-user timelapse
UID=1000
GID=1000
Name=timelapse
Timestamp=Tue 2020-04-07 16:16:20 EDT
TimestampMonotonic=3291000946930
RuntimePath=/run/user/1000
Service=user@1000.service
Slice=user-1000.slice
Display=411982
State=active
Sessions=412092 411982 163185
IdleHint=no
IdleSinceHint=0
IdleSinceHintMonotonic=0
Linger=yes

The status output looks correct to me.

$ systemctl --user status ffmpeg-timelapse.target 
● ffmpeg-timelapse.target - Triggers the individual timelapse units for each camera.
   Loaded: loaded (/home/timelapse/.config/systemd/user/ffmpeg-timelapse.target; static; vendor preset: enabled)
   Active: active since Sat 2020-06-06 10:50:42 EDT; 1h 23min ago

$ systemctl --user status ffmpeg-timelapse.timer 
● ffmpeg-timelapse.timer - Runs ffmpeg timelapse units every 5 minutes
   Loaded: loaded (/home/timelapse/.config/systemd/user/ffmpeg-timelapse.timer; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-06-06 12:13:25 EDT; 1min 1s ago

$ systemctl --user status ffmpeg-timelapse01-front-yard.service 
● ffmpeg-timelapse01-front-yard.service - Front Yard Timelapse Unit
   Loaded: loaded (/home/timelapse/.config/systemd/user/ffmpeg-timelapse01-front-yard.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2020-06-06 12:14:03 EDT; 35s ago
  Process: 4491 ExecStart=/bin/bash -ac '. camera01.conf ; exec ffmpeg-timelapse.sh'
 Main PID: 4491 (code=exited, status=0/SUCCESS)

Below is the output of journalctl -xe

Jun 06 12:13:25 srv01 systemd[26482]: Started Runs ffmpeg timelapse units every minute.
-- Subject: Unit UNIT has finished start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit UNIT has finished starting up.
-- 
-- The start-up result is done.
Jun 06 12:14:02 srv01 systemd[26482]: Started Front Yard Timelapse Unit.
-- Subject: Unit UNIT has finished start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit UNIT has finished starting up.
-- 
-- The start-up result is done.
1

I determined the issue by looking at the systemctl --user list-units --all ffmpeg* output. The ffmpeg-timelapse.target was remaining loaded/active/active. Prior to the actual triggered event the ffmpeg-timelapse.timer have the SUB set to waiting.

UNIT                                LOAD   ACTIVE     SUB     JOB   DESCRIPTION                                             
ffmpeg-timelapse.target             loaded active     active  start Triggers the individual timelapse units for each camera.
ffmpeg-timelapse.timer              loaded active     running       Runs ffmpeg timelapse units every minute                

The fault lies in the [Unit] configuration of the ffmpeg-timelapse.target. I needed to add the oneshot configuration to it, otherwise the target unit remained active.

$ cat ffmpeg-timelapse.target
[Unit]
Type=oneshot
Description=Triggers the individual timelapse units for each camera.
StopWhenUnneeded=yes

It's now repeating every minute as expected.

$ systemctl --user list-timers 
NEXT                         LEFT     LAST                         PASSED UNIT                   ACTIVATES
Sat 2020-06-06 12:58:00 EDT  13s left Sat 2020-06-06 12:57:42 EDT  3s ago ffmpeg-timelapse.timer ffmpeg-timelapse.target

This is what the units look like now.

UNIT                                  LOAD   ACTIVE   SUB     DESCRIPTION                                             
ffmpeg-timelapse01-front-yard.service loaded inactive dead    Front Yard Timelapse Unit                               
ffmpeg-timelapse.target               loaded inactive dead    Triggers the individual timelapse units for each camera.
ffmpeg-timelapse.timer                loaded active   waiting Runs ffmpeg timelapse units every minute       

Status output for each one.

$ systemctl --user status ffmpeg-timelapse.timer
● ffmpeg-timelapse.timer - Runs ffmpeg timelapse units every minute
   Loaded: loaded (/home/timelapse/.config/systemd/user/ffmpeg-timelapse.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Sat 2020-06-06 12:59:30 EDT; 3min 43s ago

$ systemctl --user status ffmpeg-timelapse.target 
● ffmpeg-timelapse.target - Triggers the individual timelapse units for each camera.
   Loaded: loaded (/home/timelapse/.config/systemd/user/ffmpeg-timelapse.target; static; vendor preset: enabled)
   Active: inactive (dead) since Sat 2020-06-06 13:03:11 EDT; 6s ago

$ systemctl --user status ffmpeg-timelapse01-front-yard.service 
● ffmpeg-timelapse01-front-yard.service - Front Yard Timelapse Unit
   Loaded: loaded (/home/timelapse/.config/systemd/user/ffmpeg-timelapse01-front-yard.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2020-06-06 13:03:12 EDT; 8s ago
  Process: 9607 ExecStart=/bin/bash -ac '. camera01.conf ; exec ffmpeg-timelapse.sh'
 Main PID: 9607 (code=exited, status=0/SUCCESS)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.