Linux – systemd oneshot server to run every x days

linuxsystemd

I was hoping to run a command every 85 days using systemd. I have created a timer and a service for the command, but I can't get the timer started. I am hoping to get the command to run every 85, not at boot and to run even if the server is restarted during the 85 day period.

/etc/systemd/system/my.service

[Unit]
description=Do my task

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/myTask

/etc/systemd/system/my.timer

[Unit]
Description=Timer to do my task

[Timer]
OnUnitActiveSec=85d
Unit=my.service
Persistent=true

After attempts to start it using systemctl start my.timer, the error messages I have been getting are:

my.timer: Refusing to start, unit to trigger not loaded.
Failed to start Timer to do my task.

Best Answer

Change description in your service file to Description. Otherwise, it'll be printing errors in the logs like below:

Unknown lvalue 'description' in section 'Unit'

Also, try using these commands to troubleshoot problems with your timer file:

systemctl status my.timer
journalctl -xe

Update your post if you see any errors in the logs and don't know how to fix them.