You are not logged in.
Hello everyone,
I have a timer which is performed on my remote server daily, running a simple shell-script that creates a folder and file.
It works only when I connect to my server via ssh. It doesn’t work by itself, at least not as I expect — I thought daily timers start at 00:00 and if the server isn’t running, then at the moment server starts, if Persistent=true.
It looks like the timer is scheduled to run at the midnight, but it doesn’t.
systemctl --user list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Sat 2020-02-01 00:00:00 EET 12h left Fri 2020-01-31 10:37:45 EET 22min ago daily.timer daily.serviceI may suspect my server to not running (i.e. sleeping), but no, it serves files for me and performs sync with syncthing, may do other tasks, but not the timer, not till the point I connect via ssh. The created date of the folder and file is the moment I connect. Since I sync the said folder with syncthing, it appears on my devices only after I ssh into my server.
I would prefer to have the task done in the early morning, not when I ssh, because I don’t need to maintain my server daily.
Is there something I may do wrong or misunderstand?
***
My files, just in case.
daily.service
[Unit]
Description=Add Day Directory
[Service]
WorkingDirectory=/home/walter/
ExecStart=/home/walter/.scripts/daily.shdaily.timer
[Unit]
Description=Add Day Directory
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target***
Update: the problem was solved, and the solution is in the wiki: Automatic start-up of systemd user instances, as @WorMzy mentioned.
Last edited by walteweiss (2020-02-01 18:17:45)
Russia is committing genocide on Ukraine right now (2022—2025), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events. Thank you.
Offline
Please provide the journal of both the timer and the corresponding service, so that we can actually see what's going on.
Also the content of the script might be interesting.
A shot in the dark is, that the script uses some program that requires a login session, so that it fails if there is none i.e. when you are not logged in - via ssh or otherwise.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
If you want this to be run when you're not logged in, I recommend using a system session timer rather than a user session timer. If you're really set on using a user session, you'll need to force the user session to start at boot: https://wiki.archlinux.org/index.php/Sy … _instances
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Please provide the journal of both the timer and the corresponding service, so that we can actually see what's going on.
Excuse me, but do you mind pointing me into how this should be done? I see wiki:Systemd/Journal, but I couldn't find anything timer-related. I haven't worked with journaling yet.
Also the content of the script might be interesting.
Yes, my bad I didn't provide it right away, but the script is super simple:
#!/bin/sh
mkdir $(date +"%m-%d-%a") && cd $_
curl v2.wttr.in > WeatherA shot in the dark is, that the script uses some program that requires a login session, so that it fails if there is none i.e. when you are not logged in - via ssh or otherwise.
I believe that is correct, as WorMzy suggested:
If you want this to be run when you're not logged in, I recommend using a system session timer rather than a user session timer. If you're really set on using a user session, you'll need to force the user session to start at boot: https://wiki.archlinux.org/index.php/Sy … _instances
Thank you, I believe that is exactly what happens. I wasn’t sure user timers would work, and it wasn’t clear for me from reading the wiki about it. But it also wasn’t obvious for me when the error happened. I forced the user session to start at boot, as of now, and I'll check the script tomorrow, whether it'll work as I expect.
I am curious why using a system session is better? What are the downsides of having it forced with user session?
Russia is committing genocide on Ukraine right now (2022—2025), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events. Thank you.
Offline
I am changing this as [SOLVED], since it works.
What I did is performed
# loginctl enable-linger username(Am I allowed to just copy the code from the wiki? I guess if you came to this post years later, you’d better check the wiki first, since things may change)
Automatic start-up of systemd user instances, as @WorMzy mentioned.
Last edited by walteweiss (2020-02-01 18:16:54)
Russia is committing genocide on Ukraine right now (2022—2025), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events. Thank you.
Offline
I am curious why using a system session is better? What are the downsides of having it forced with user session?
One possible downside is that even things you don't want to keep running after a user logs out will if you enable linger. I don't have any examples of that, but to me 'enable-linger' seems like using a sledgehammer to crack a nut. If you don't have root access on the system (and therefore can't write/enable a system timer), then it may be your only option, but if you do have the option to write a system timer, that seems like the more appropriate option.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Azzz
I don't have any examples of that
user sessions of Syncthing work that way
Calamity from the skies
Offline
user sessions of Syncthing work that way
Yes, btw I have Syncthing working for my user, and it worked before I enabled the linger. That what made me think this timer script would work as well.
One possible downside is that even things you don't want to keep running after a user logs out will if you enable linger.
Unfortunately I am too new to understand what may stay running, and how this may be a worse solution. Thank you for your advice, I'll consider rewriting the script to run it as a system script, not a user one.
Russia is committing genocide on Ukraine right now (2022—2025), please help Ukraine as much as you can. That’s the turning point of the democracy vs tyranny war, and if Ukraine loses, everyone in the democracy world will. You can donate to Ukraine here: savelife.in.ua/en/donate or help with spreading the information about the ongoing events. Thank you.
Offline