You are not logged in.

#1 2015-09-12 02:42:56

Oblivion7
Member
From: Outside your universe.
Registered: 2015-08-29
Posts: 78

Systemd timer not running script.

Hello so i have been playing around with systemd timers and i want to make on that offers to update my system every week (i have it set to 1min atm just to test not gonna use it)but whenever the time comes nothing happens
this is the update.timer

[Unit]
Description=Runs optional system upgrade weekly

[Timer]
OnCalendar=*:0/01
Persistent=true
Unit=update.service

[Install]
WantedBy=timers.target

This is the service

[Unit]
Description=update

[Service]
Type=oneshot
ExecStart=/usr/local/bin/updatemsg.sh

and this is the script

#!/bin/bash

kdialog --title "Scheduled system update" --yesno "System update \
.\n Do you want to update now?"

if [ $? = 0 ]; then
konsole -e bash -c "sudo tar -cjf /.Backups/Pacman-Db_Backup/pacman-database.tar.bz2 /var/lib/pacman/local && sudo pacman -Syu && sudo sh /usr/local/bin/Pacman-Clean.sh" 
fi

exit 0

Thank you for your time~

Last edited by Oblivion7 (2015-09-12 02:44:36)


Anyone who has never made a mistake has never tried anything new. ~Albert Einstein

Offline

#2 2015-09-12 05:20:56

severach
Member
Registered: 2015-05-23
Posts: 192

Re: Systemd timer not running script.

systemctl status update.service
systemctl status update.timer
journalctl _SYSTEMD_UNIT=update.service

Are they running at the scheduled times? Any error messages? I'm expecting one about "cannot open display."

Offline

#3 2015-09-12 06:24:55

headkase
Member
Registered: 2011-12-06
Posts: 1,977

Re: Systemd timer not running script.

Did you make the script executable?

chmod +x <script>

Offline

#4 2015-09-12 15:42:11

Oblivion7
Member
From: Outside your universe.
Registered: 2015-08-29
Posts: 78

Re: Systemd timer not running script.

severach wrote:
systemctl status update.service
systemctl status update.timer
journalctl _SYSTEMD_UNIT=update.service

Are they running at the scheduled times? Any error messages? I'm expecting one about "cannot open display."

Hmmm odd, these are the outputs of each most seem fine except one.

sudo systemctl status update.service
[sudo] password for oblivion: 
● update.service - update
   Loaded: loaded (/usr/lib/systemd/system/update.service; static; vendor preset: disabled)
   Active: inactive (dead)
[oblivion@archbox ~]$ sudo systemctl status update.timer
● update.timer - Runs optional system upgrade weekly
   Loaded: loaded (/usr/lib/systemd/system/update.timer; enabled; vendor preset: disabled)
   Active: active (waiting) since Sat 2015-09-12 11:34:06 CDT; 3min 10s ago
[oblivion@archbox ~]$ sudo journalctl _SYSTEMD_UNIT=update.service
-- Logs begin at Tue 2015-09-01 14:38:52 CDT, end at Sat 2015-09-12 11:39:04 CDT. --
Sep 11 22:21:21 archbox updatemsg.sh[547]: kdialog: cannot connect to X server
Sep 11 22:22:03 archbox updatemsg.sh[1255]: kdialog: cannot connect to X server
Sep 11 22:23:01 archbox updatemsg.sh[1289]: kdialog: cannot connect to X server
-- Reboot --
Sep 11 22:24:39 archbox updatemsg.sh[532]: kdialog: cannot connect to X server
Sep 11 22:25:05 archbox updatemsg.sh[869]: kdialog: cannot connect to X server
Sep 11 22:26:01 archbox updatemsg.sh[1361]: kdialog: cannot connect to X server
Sep 11 22:27:08 archbox updatemsg.sh[1459]: kdialog: cannot connect to X server
Sep 11 22:28:00 archbox updatemsg.sh[1562]: kdialog: cannot connect to X server
Sep 11 22:29:09 archbox updatemsg.sh[1601]: kdialog: cannot connect to X server
Sep 11 22:30:02 archbox updatemsg.sh[1637]: kdialog: cannot connect to X server
Sep 11 22:31:09 archbox updatemsg.sh[1992]: kdialog: cannot connect to X server
Sep 11 22:32:02 archbox updatemsg.sh[2101]: kdialog: cannot connect to X server
Sep 11 22:33:08 archbox updatemsg.sh[2178]: kdialog: cannot connect to X server
Sep 11 22:34:02 archbox updatemsg.sh[2214]: kdialog: cannot connect to X server
Sep 11 22:35:02 archbox updatemsg.sh[2250]: kdialog: cannot connect to X server
Sep 11 22:36:02 archbox updatemsg.sh[2413]: kdialog: cannot connect to X server
Sep 11 22:37:02 archbox updatemsg.sh[2447]: kdialog: cannot connect to X server
Sep 11 22:38:02 archbox updatemsg.sh[2482]: kdialog: cannot connect to X server
Sep 11 22:39:02 archbox updatemsg.sh[2515]: kdialog: cannot connect to X server
Sep 11 22:40:02 archbox updatemsg.sh[2550]: kdialog: cannot connect to X server
Sep 11 22:41:02 archbox updatemsg.sh[2698]: kdialog: cannot connect to X server
Sep 11 22:42:02 archbox updatemsg.sh[2742]: kdialog: cannot connect to X server
Sep 11 22:43:02 archbox updatemsg.sh[2803]: kdialog: cannot connect to X server
Sep 11 22:44:02 archbox updatemsg.sh[2835]: kdialog: cannot connect to X server
Sep 11 22:45:02 archbox updatemsg.sh[2871]: kdialog: cannot connect to X server
Sep 11 22:46:02 archbox updatemsg.sh[3015]: kdialog: cannot connect to X server

yeah i think something is up with this one. wink

EDIT: maybe because im trying to run them with sudo?

Last edited by Oblivion7 (2015-09-12 15:54:51)


Anyone who has never made a mistake has never tried anything new. ~Albert Einstein

Offline

#5 2015-09-12 15:54:40

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Systemd timer not running script.

You should put your own (system) services in /etc/systemd/system, not /usr/lib/system.

But this script (starting GUI programs and using sudo) really looks like it's intended to be started as a user service, so it should be in /etc/systemd/user, or just for your user in ~/.config/systemd/user. Disable the system timer, enable the user timer and things should be much better.

Last edited by Raynman (2015-09-12 15:55:24)

Offline

#6 2015-09-12 16:35:07

Oblivion7
Member
From: Outside your universe.
Registered: 2015-08-29
Posts: 78

Re: Systemd timer not running script.

Raynman wrote:

You should put your own (system) services in /etc/systemd/system, not /usr/lib/system.

But this script (starting GUI programs and using sudo) really looks like it's intended to be started as a user service, so it should be in /etc/systemd/user, or just for your user in ~/.config/systemd/user. Disable the system timer, enable the user timer and things should be much better.

would the "WantedBy=" target change? (nvm didnt really have a good grip on what it ment now i do)

Last edited by Oblivion7 (2015-09-12 16:50:52)


Anyone who has never made a mistake has never tried anything new. ~Albert Einstein

Offline

#7 2015-09-12 17:08:10

Oblivion7
Member
From: Outside your universe.
Registered: 2015-08-29
Posts: 78

Re: Systemd timer not running script.

Raynman wrote:

You should put your own (system) services in /etc/systemd/system, not /usr/lib/system.

But this script (starting GUI programs and using sudo) really looks like it's intended to be started as a user service, so it should be in /etc/systemd/user, or just for your user in ~/.config/systemd/user. Disable the system timer, enable the user timer and things should be much better.

Idk if I did this right because i get the same error.I moved my update.timer & update.service to /etc/systemd/system and then i moved my script to /etc/systemd/user (was gonna move it to ~/.config/systemd/user. but it seems the systemd folder does not exist and wasnt sure if i should make it) then i just used

sudo systemctl start update.timer

sudo systemctl enable update.timer

I was trying to use sudo  systemctl --user start update.timer
but it couldn't find directories

man im a mess lol.

Last edited by Oblivion7 (2015-09-12 17:09:24)


Anyone who has never made a mistake has never tried anything new. ~Albert Einstein

Offline

#8 2015-09-12 18:02:18

snakeroot
Member
Registered: 2012-10-06
Posts: 164

Re: Systemd timer not running script.

As predicted by severach:

oblivion's journal wrote:

Sep 11 22:21:21 archbox updatemsg.sh[547]: kdialog: cannot connect to X server

I strongly suspect that this is due to the absence of $DISPLAY variable. systemd services are run in a very sterile environment which inherits no variables. This causes no end of problems for running X apps.

You may wish to review the Wiki's Systemd/User page and, in particular, its sections DISPLAY and Note about X Applications.

Regards,

Offline

#9 2015-09-12 18:30:12

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Systemd timer not running script.

Raynman wrote:

You should put your own (system) services in /etc/systemd/system, not /usr/lib/system.

But this script (starting GUI programs and using sudo) really looks like it's intended to be started as a user service, so it should be in /etc/systemd/user, or just for your user in ~/.config/systemd/user.

Because I edited this last sentence a bit after I wrote it, I suppose it might seem like I wanted you to move the script (instead of the service/timer) to a directory containing services, but that doesn't make sense. I was talking about services/.service files and distinguishing between system and user services. Actually I should say units; services are perhaps the most common type of unit, timers are another. systemd uses different directories for system and user units (see table 2 in the systemd.unit man page).

You can leave the script in /usr/local/bin, or (if you keep the units in your $HOME) use something like ~/bin (perhaps you already have a directory like that with personal scripts included in your $PATH?).

Oblivion7 wrote:

I was trying to use sudo  systemctl --user start update.timer

?? Look at what you're doing there: you tell systemctl you want the user (instead of system) manager, but you run this command as the root user. The reason you often see `sudo systemctl` is because people are dealing with system services (without --user) and then you need root privileges to make changes (`systemctl status` doesn't make changes, so that can be used as a normal user for system services too).

snakeroot wrote:

You may wish to review the Wiki's Systemd/User page and, in particular, its sections DISPLAY and Note about X Applications.

Seems a little outdated (and even though it's improved, that page still reads like a collection of workarounds and hacks, but that's not so strange since the whole systemd/user thing is a work in progress). systemd provides something like the "import-display.sh" now (has been part of the last couple of releases at least), so unless you start X in a nonstandard way, user services should be aware of the DISPLAY.

Offline

#10 2015-09-12 19:43:10

Oblivion7
Member
From: Outside your universe.
Registered: 2015-08-29
Posts: 78

Re: Systemd timer not running script.

Raynman wrote:
Raynman wrote:

You should put your own (system) services in /etc/systemd/system, not /usr/lib/system.

But this script (starting GUI programs and using sudo) really looks like it's intended to be started as a user service, so it should be in /etc/systemd/user, or just for your user in ~/.config/systemd/user.

Because I edited this last sentence a bit after I wrote it, I suppose it might seem like I wanted you to move the script (instead of the service/timer) to a directory containing services, but that doesn't make sense. I was talking about services/.service files and distinguishing between system and user services. Actually I should say units; services are perhaps the most common type of unit, timers are another. systemd uses different directories for system and user units (see table 2 in the systemd.unit man page).

You can leave the script in /usr/local/bin, or (if you keep the units in your $HOME) use something like ~/bin (perhaps you already have a directory like that with personal scripts included in your $PATH?).

So i moved my timer and service to /etc/systemd/user and my script back to /usr/local/bin and now the script starts!! the thing is the only problem now is that after i press yes in the kdialog the konsole is not opened to finish the script.

Last edited by Oblivion7 (2015-09-12 20:05:00)


Anyone who has never made a mistake has never tried anything new. ~Albert Einstein

Offline

#11 2015-09-12 21:23:52

snakeroot
Member
Registered: 2012-10-06
Posts: 164

Re: Systemd timer not running script.

Raynman wrote:

Seems a little outdated (and even though it's improved, that page still reads like a collection of workarounds and hacks, but that's not so strange since the whole systemd/user thing is a work in progress). systemd provides something like the "import-display.sh" now (has been part of the last couple of releases at least), so unless you start X in a nonstandard way, user services should be aware of the DISPLAY.

Ah, quite right. My apologies; I haven't messed with this in quite some time. I've updated the Wiki to try to reflect the current state, but would be most grateful if you could give it another read.

Offline

#12 2015-09-13 03:00:43

Oblivion7
Member
From: Outside your universe.
Registered: 2015-08-29
Posts: 78

Re: Systemd timer not running script.

snakeroot wrote:
Raynman wrote:

Seems a little outdated (and even though it's improved, that page still reads like a collection of workarounds and hacks, but that's not so strange since the whole systemd/user thing is a work in progress). systemd provides something like the "import-display.sh" now (has been part of the last couple of releases at least), so unless you start X in a nonstandard way, user services should be aware of the DISPLAY.

Ah, quite right. My apologies; I haven't messed with this in quite some time. I've updated the Wiki to try to reflect the current state, but would be most grateful if you could give it another read.

so could this be the reason why the script that's executed can start my kdialog but once i press yes konsole doesn't  open?

EDIT: Ok this is really odd i just had a feeling if i had konsole open when i pressed yes when the timer went of it would work and IT DID! Would you know why something like this would happen?

Last edited by Oblivion7 (2015-09-13 03:13:09)


Anyone who has never made a mistake has never tried anything new. ~Albert Einstein

Offline

Board footer

Powered by FluxBB