-
Create
myunit.service
. Only[Service]
is needed, with anExecStart=
-
Create
myunit.timer
. It needs[Timer]
with anOnCalendar=
or similar. It needs[Install]
withWantedBy=timers.target
-
Enable both units. The
.service
unit will issue a warning due to missing[Install]
. This is not a problemsystemctl --user enable $PWD/myunit.service systemctl --user enable $PWD/myunit.timer
Now you can start
the timer when you want, for the .service
to be executed according to schedule.
To verify the status of timers, use systemctl list-timers
.
At this point, the timer will only start once the user logs in (if installed for root it should start on boot). If you want the timer to start automatically on boot:
loginctl enable-linger [user]
If you want to run a service on a schedule (or once) only temporarily (lose it after poweroff), you can use systemd-run
. The .service
and .timer
units are created automatically for you. For example:
systemd-run --user [--unit=myunit] --on-calendar=hourly /bin/touch /tmp/test