I am attempting to create and install on Bionic a custom pair of systemd timer & service units for running a command periodically. I know that the files should be placed in /etc/systemd/system
and then I should run systemctl daemon-reload
, but I'm not clear on whether I need to enable or start anything in order for the timer to be fully installed and "running," and the few articles I can find that address this point all give different information.
My .timer
file is:
[Unit]
Description=Run custom command periodically
[Timer]
Unit=my-custom-command.service
OnCalendar=*-*-* 0/8:00:00
[Install]
WantedBy=timers.target
My .service
file is:
[Unit]
Description=Run a custom command
OnFailure=mail-systemd-failure@%n.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/custom-command
User=dedicated-user
Group=dedicated-user
The conflicting articles I've read are:
This article says to run:
systemctl daemon-reload systemctl enable $NAME.timer systemctl start $NAME
As I understand it, the latter command is the same as
systemctl start $NAME.service
, which I would expect to immediately run the command defined by the service, which is not what I want to do.This gist says to just run:
systemctl daemon-reload systemctl start $NAME.timer
This article says to run:
systemctl enable $NAME.timer systemctl start $NAME.timer
So do I enable and/or start the timer (or its service?), and what exactly is the difference between the two? Do the commands I need to run change depending on whether the unit files are newly installed or being reloaded after an edit?