I’m trying to create a service for a user that activates every 10 minutes. Everything works if I start the timer manually, but after a restart it’s inactive. What am I doing wrong?
[Unit]
Description=HyperHDR Night switch
[Service]
Type=simple
ExecStart=/home/mike/Skrypty/night_led.sh
[Unit]
Description=Run my script every 10 minutes
[Timer]
OnCalendar=*:0/10
Persistent=true
OnBootSec=10
[Install]
WantedBy=timers.target
after boot:
systemctl --user status hyperhdr-switch.timer
○ hyperhdr-switch.timer - Run my script every 10 minutes
Loaded: loaded (/home/mike/.config/systemd/user/hyperhdr-switch.timer; enabled; preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● hyperhdr-switch.service
and after systemctl --user start hyperhdr-switch.timer
● hyperhdr-switch.timer - Run my script every 10 minutes
Loaded: loaded (/home/mike/.config/systemd/user/hyperhdr-switch.timer; enabled; preset: enabled)
Active: active (waiting) since Wed 2024-12-18 10:40:19 CET; 2s ago
Invocation: ec8854326b654f889386cb23cd0212b6
Trigger: Wed 2024-12-18 10:41:00 CET; 37s left
Triggers: ● hyperhdr-switch.service
gru 18 10:40:19 ryzen systemd[884]: Started Run my script every 10 minutes.
i already do that. The timer is showing an “enabled” status, but it becomes inactive after a restart. I know I could add a command “systemctl enable --user my-timer.timer” to the startup programs, but that defeats the whole purpose of services.
mike@ryzen ~ [1]> ls ~/.config/systemd/user/
hyperhdr-switch.service hyperhdr-switch.timer timers.target.wants/
mike@ryzen ~> ls ~/.config/systemd/user/timers.target.wants/
hyperhdr-switch.timer@
it’s enabled but not started after reboot…
systemctl --user list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
- - - - hyperhdr-switch.timer hyperhdr-switch.service
1 timers listed.
i need to start it manually
systemctl --user status hyperhdr-switch.timer
○ hyperhdr-switch.timer - Run my script every 10 minutes
Loaded: loaded (/home/mike/.config/systemd/user/hyperhdr-switch.timer; enabled; preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● hyperhdr-switch.service
mike@ryzen ~ [3]> systemctl --user start hyperhdr-switch.timer
mike@ryzen ~> systemctl --user status hyperhdr-switch.timer
● hyperhdr-switch.timer - Run my script every 10 minutes
Loaded: loaded (/home/mike/.config/systemd/user/hyperhdr-switch.timer; enabled; preset: enabled)
Active: active (running) since Wed 2024-12-18 11:57:58 CET; 2s ago
Invocation: b09f1467db024df3939482e4637e8e09
Trigger: n/a
Triggers: ● hyperhdr-switch.service
gru 18 11:57:58 ryzen systemd[894]: Started Run my script every 10 minutes.
mike@ryzen ~> systemctl --user list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2024-12-18 11:59:00 CET 53s Wed 2024-12-18 11:58:00 CET 5s ago hyperhdr-switch.timer hyperhdr-switch.service
1 timers listed.
Could you please confirm that your ~/.config/systemd/user/ directory contains the files hyperhdr-switch.service & hyperhdr-switch.timer?
Also, please confirm that your ~/.config/systemd/user/timers.target.wants/ directory contains hyperhdr-switch.timer as a symlink to ~/.config/systemd/user/hyperhdr-switch.timer.
If they look fine, then try the following commands:
Please make a note of any warnings or error messages that occur when you enable the timer and post them here.
Also, as the timer is not starting at login, maybe you should give the system a little more time to load the desktop and services before starting it. Would making the timer wait 30-60 seconds cause any issues? That would just require a change to the OnStartupSec=10 line.
After you make any changes and save the file, make sure you run:
I’m scratching my head too. The only suggestion I have left is to run the following commands to see if there are any issues with the hyperhdr-switch.service file that may be preventing the timer from running:
systemctl --user status hyperhdr-switch.service
journalctl --user -xeu hyperhdr-switch.service
You might as well run the journalctl on the timer as well (if you haven’t already done so):
I’ve been using a template from the first timer I created a couple of years ago to create my timers since then. I might go through them all over the weekend & remove any unnecessary lines.
It works fine with or without spaces. Most of my timers have a space in either the OnStartupSec= or the OnUnitActiveSec= values, and they’ve worked without any problems. Although I just now removed the spaces in all of them.
Systemd is quite good at working out what the user intends when they enter a duration.