You are not logged in.

#1 2019-03-16 18:21:34

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

[SOLVED] Systemd errors

I am trying to make a systemd script that runs once after waking up from suspension of the system. But it keeps giving me this:

● kbd-and-background-fix.service - Fixes wallpaper after suspend and resets keyboard layout to UK
   Loaded: loaded (/etc/systemd/system/kbd-and-background-fix.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2019-03-16 18:10:20 GMT; 5s ago
  Process: 4579 ExecStartPre=/bin/sleep 30 (code=exited, status=0/SUCCESS)
  Process: 4765 ExecStart=/usr/bin/kbd-and-background-fix (code=exited, status=1/FAILURE)
 Main PID: 4765 (code=exited, status=1/FAILURE)

Mar 16 18:09:50 Kevin-B350MA systemd[1]: Starting Fixes wallpaper after suspend and resets keyboard layout to UK...
Mar 16 18:10:20 Kevin-B350MA kbd-and-background-fix[4765]: Cannot open display "default display"
Mar 16 18:10:20 Kevin-B350MA kbd-and-background-fix[4765]: Failed to open connection to "session" message bus: Server address of type unix was missing argument path or abstract
Mar 16 18:10:20 Kevin-B350MA systemd[1]: kbd-and-background-fix.service: Main process exited, code=exited, status=1/FAILURE
Mar 16 18:10:20 Kevin-B350MA systemd[1]: kbd-and-background-fix.service: Failed with result 'exit-code'.
Mar 16 18:10:20 Kevin-B350MA systemd[1]: Failed to start Fixes wallpaper after suspend and resets keyboard layout to UK

The script is here:

[Unit]
Description=Fixes wallpaper after suspend and resets keyboard layout to UK
After=suspend.target

[Service]
Type=oneshot
User=kevin
ExecStart=/usr/bin/kbd-and-background-fix

[Install]
WantedBy=multi-user.target suspend.target

The ExecStart script:

#!/bin/bash

dbus-send --type=method_call  --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval "string:global.reexec_self()"
setxkbmap gb

What is wrong with my script?

Last edited by Vectorlocity (2019-03-17 17:45:56)

Offline

#2 2019-03-16 18:48:36

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Systemd errors

Isn't this an XY-problem?

To set the keyboard in X use localectl(1) (or an Xorg configuration file).

But anyway:

Vectorlocity wrote:
Mar 16 18:10:20 Kevin-B350MA kbd-and-background-fix[4765]: Cannot open display "default display"
Mar 16 18:10:20 Kevin-B350MA kbd-and-background-fix[4765]: Failed to open connection to "session" message bus: Server address of type unix was missing argument path or abstract

Enable the unit file as a --user .service (and drop the User= line), that should set DISPLAY correctly, I think.

For the dbus error try importing the DBUS_SESSION_BUS_ADDRESS environment, see https://superuser.com/questions/759759/ … ds-on-xorg & https://wiki.archlinux.org/index.php/Sy … XAUTHORITY for more on this.

Vectorlocity wrote:

What is wrong with my script?

You have a bash shebang but the script contains no bashisms.

Replacing it with a /bin/sh shebang will make no practical difference in a stock Arch system (/bin/sh is linked to bash[1]) but it will make me feel better smile

[1] yikes


Jin, Jîyan, Azadî

Offline

#3 2019-03-16 19:16:21

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Head_on_a_Stick wrote:

Isn't this an XY-problem?

To set the keyboard in X use localectl(1) (or an Xorg configuration file).

But anyway:

Vectorlocity wrote:
Mar 16 18:10:20 Kevin-B350MA kbd-and-background-fix[4765]: Cannot open display "default display"
Mar 16 18:10:20 Kevin-B350MA kbd-and-background-fix[4765]: Failed to open connection to "session" message bus: Server address of type unix was missing argument path or abstract

Enable the unit file as a --user .service (and drop the User= line), that should set DISPLAY correctly, I think.

For the dbus error try importing the DBUS_SESSION_BUS_ADDRESS environment, see https://superuser.com/questions/759759/ … ds-on-xorg & https://wiki.archlinux.org/index.php/Sy … XAUTHORITY for more on this.

Vectorlocity wrote:

What is wrong with my script?

You have a bash shebang but the script contains no bashisms.

Replacing it with a /bin/sh shebang will make no practical difference in a stock Arch system (/bin/sh is linked to bash[1]) but it will make me feel better smile

[1] yikes

OK I will try smile

Offline

#4 2019-03-16 19:21:07

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

I'm getting this when trying to enable with --user:

kevin@Kevin-B350MA:/etc/systemd/system$ sudo systemctl --user enable kbd-and-background-fix.service 
Failed to connect to bus: No such file or directory

Rebooting my computer fixes it but is there a permanent way to fix it? It seems to occur only after suspension of my system.

EDIT 1: DBUS_SESSION_BUS_ADDRESS seems to be set correctly.

EDIT 2: Output of these commands:

kevin@Kevin-B350MA:~$ echo $XDG_RUNTIME_DIR
/run/user/1000
kevin@Kevin-B350MA:/~$ echo $DBUS_SESSION_BUS_ADDRESS
unix:path=/run/user/1000/bus
kevin@Kevin-B350MA:~$ echo $DISPLAY
:1
kevin@Kevin-B350MA:~$ echo $XAUTHORITY
/run/user/1000/gdm/Xauthority
kevin@Kevin-B350MA:~$ 

Last edited by Vectorlocity (2019-03-16 19:27:04)

Offline

#5 2019-03-16 19:33:37

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Systemd errors

Vectorlocity wrote:

I'm getting this when trying to enable with --user:

kevin@Kevin-B350MA:/etc/systemd/system$ sudo systemctl --user enable kbd-and-background-fix.service 
Failed to connect to bus: No such file or directory

Enable the .service as your normal user (without `sudo`) and place the unit file in $HOME, as explained on the ArchWiki page in my previous link.

Vectorlocity wrote:

DBUS_SESSION_BUS_ADDRESS seems to be set correctly.

Did you try

systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS

as suggested by the StackExchange thread to which I linked?


Jin, Jîyan, Azadî

Offline

#6 2019-03-16 19:39:48

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Head_on_a_Stick wrote:
Vectorlocity wrote:

I'm getting this when trying to enable with --user:

kevin@Kevin-B350MA:/etc/systemd/system$ sudo systemctl --user enable kbd-and-background-fix.service 
Failed to connect to bus: No such file or directory

Enable the .service as your normal user (without `sudo`) and place the unit file in $HOME, as explained on the ArchWiki page in my previous link.

Vectorlocity wrote:

DBUS_SESSION_BUS_ADDRESS seems to be set correctly.

Did you try

systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS

as suggested by the StackExchange thread to which I linked?

Yes, I did.

EDIT: I don't quite get what you mean by moving the unit file part. Where do I move my .service file to? I've tried my home directory, then systemd says it doesn't exist.

EDIT 2: Gottit smile. I just need to test it now.

Last edited by Vectorlocity (2019-03-16 19:46:02)

Offline

#7 2019-03-16 19:53:11

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Head_on_a_Stick wrote:
Vectorlocity wrote:

I'm getting this when trying to enable with --user:

kevin@Kevin-B350MA:/etc/systemd/system$ sudo systemctl --user enable kbd-and-background-fix.service 
Failed to connect to bus: No such file or directory

Enable the .service as your normal user (without `sudo`) and place the unit file in $HOME, as explained on the ArchWiki page in my previous link.

Vectorlocity wrote:

DBUS_SESSION_BUS_ADDRESS seems to be set correctly.

Did you try

systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS

as suggested by the StackExchange thread to which I linked?

Now I have this:

● kbd-and-background-fix.service - Fixes wallpaper after suspend and resets keyboard layout to UK
   Loaded: loaded (/home/kevin/.config/systemd/user/kbd-and-background-fix.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-03-16 19:51:23 GMT; 6s ago
  Process: 9158 ExecStart=/usr/bin/kbd-and-background-fix (code=exited, status=216/GROUP)
 Main PID: 9158 (code=exited, status=216/GROUP)

Mar 16 19:51:23 Kevin-B350MA systemd[848]: Starting Fixes wallpaper after suspend and resets keyboard layout to UK...
Mar 16 19:51:23 Kevin-B350MA systemd[9158]: kbd-and-background-fix.service: Failed to determine supplementary groups: Operation not permitted
Mar 16 19:51:23 Kevin-B350MA systemd[9158]: kbd-and-background-fix.service: Failed at step GROUP spawning /usr/bin/kbd-and-background-fix: Operation not permitted
Mar 16 19:51:23 Kevin-B350MA systemd[848]: kbd-and-background-fix.service: Main process exited, code=exited, status=216/GROUP
Mar 16 19:51:23 Kevin-B350MA systemd[848]: kbd-and-background-fix.service: Failed with result 'exit-code'.
Mar 16 19:51:23 Kevin-B350MA systemd[848]: Failed to start Fixes wallpaper after suspend and resets keyboard layout to UK.

I haven't changed anything in the files.

Offline

#8 2019-03-16 20:27:28

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Systemd errors

OK, stop for a minute.

What is it you are actually trying to do here?

If you want to set the keyboard then you don't need to use a systemd unit file, see my previous posts for the "correct" method.

And I'm sure there's a better way to set the wallpaper, if that's the other thing your script is attempting.


Jin, Jîyan, Azadî

Offline

#9 2019-03-16 20:29:16

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Head_on_a_Stick wrote:

OK, stop for a minute.

What is it you are actually trying to do here?

If you want to set the keyboard then you don't need to use a systemd unit file, see my previous posts for the "correct" method.

And I'm sure there's a better way to set the wallpaper, if that's the other thing your script is attempting.

I've tried the first method of the keyboard layout months ago - kept resetting itself after suspension.
My script is attempting to reload the wallpaper because of a bug with wallpapers and Nvidia graphics cards that makes the wallpaper turn into static or black upon waking from suspension.

Offline

#10 2019-03-16 20:35:48

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Systemd errors

Vectorlocity wrote:

I've tried the first method of the keyboard layout months ago - kept resetting itself after suspension.

And which method would that be? Please post exactly what you tried.

Were there any clues in the journal as to why it was reset?

Vectorlocity wrote:

My script is attempting to reload the wallpaper because of a bug with wallpapers and Nvidia graphics cards that makes the wallpaper turn into static or black upon waking from suspension.

Has this bug been reported? Are there any known fixes?

And for the errors shown in this post then see https://bbs.archlinux.org/viewtopic.php?id=233035


Jin, Jîyan, Azadî

Offline

#11 2019-03-16 20:38:07

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Head_on_a_Stick wrote:
Vectorlocity wrote:

I've tried the first method of the keyboard layout months ago - kept resetting itself after suspension.

And which method would that be? Please post exactly what you tried.

Were there any clues in the journal as to why it was reset?

Vectorlocity wrote:

My script is attempting to reload the wallpaper because of a bug with wallpapers and Nvidia graphics cards that makes the wallpaper turn into static or black upon waking from suspension.

Has this bug been reported? Are there any known fixes?

And for the errors shown in this post then see https://bbs.archlinux.org/viewtopic.php?id=233035

As for the keyboard layout, no.

The bug has been reported many times, and Nvidia has come up to explain that it uses FBOs to make the rendering of each frame easier, but when the computer suspends the FBOs aren't saved.

Offline

#12 2019-03-16 20:47:03

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Head_on_a_Stick wrote:
Vectorlocity wrote:

I've tried the first method of the keyboard layout months ago - kept resetting itself after suspension.

And which method would that be? Please post exactly what you tried.

Were there any clues in the journal as to why it was reset?

Vectorlocity wrote:

My script is attempting to reload the wallpaper because of a bug with wallpapers and Nvidia graphics cards that makes the wallpaper turn into static or black upon waking from suspension.

Has this bug been reported? Are there any known fixes?

And for the errors shown in this post then see https://bbs.archlinux.org/viewtopic.php?id=233035

It works now. But still one problem.
It now doesn't work when it's supposed to. It doesn't run after system suspension. It only runs when told to.

Offline

#13 2019-03-16 20:57:41

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Systemd errors

Please stop full quoting unnecessarily, it ruins the readability of the thread.

What exactly do you mean by

It only runs when told to

Have you checked the journal for clues?

journalctl -u kbd-and-background-fix.service

And I'm a bit lost now, can we please see

systemctl --user cat kbd-and-background-fix.service --no-p

The working unit file may be useful for others experiencing this problem.


Jin, Jîyan, Azadî

Offline

#14 2019-03-16 21:19:41

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

I mean it only runs when you run systemctl start --user kbd-and-background-fix.service
Journalctl -u kbd-and-background-fix --user output:

Mar 16 20:39:18 Kevin-B350MA systemd[848]: Starting Fixes wallpaper after suspend and resets keyboard layout to UK...
Mar 16 20:39:18 Kevin-B350MA systemd[848]: kbd-and-background-fix.service: Succeeded.
Mar 16 20:39:18 Kevin-B350MA systemd[848]: Started Fixes wallpaper after suspend and resets keyboard layout to UK.
Mar 16 20:40:14 Kevin-B350MA systemd[848]: Starting Fixes wallpaper after suspend and resets keyboard layout to UK...
Mar 16 20:40:14 Kevin-B350MA systemd[848]: kbd-and-background-fix.service: Succeeded.
Mar 16 20:40:14 Kevin-B350MA systemd[848]: Started Fixes wallpaper after suspend and resets keyboard layout to UK.
Mar 16 20:44:33 Kevin-B350MA systemd[848]: Starting Fixes wallpaper after suspend and resets keyboard layout to UK...
Mar 16 20:44:34 Kevin-B350MA systemd[848]: kbd-and-background-fix.service: Succeeded.
Mar 16 20:44:34 Kevin-B350MA systemd[848]: Started Fixes wallpaper after suspend and resets keyboard layout to UK.

Unit file:

[Unit]
Description=Fixes wallpaper after suspend and resets keyboard layout to UK
After=suspend.target

[Service]
Type=oneshot
ExecStart=/usr/bin/kbd-and-background-fix

[Install]
WantedBy=multi-user.target suspend.target

Offline

#15 2019-03-16 21:35:42

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,586

Re: [SOLVED] Systemd errors

Please stop this nonsense and add /etc/X11/xorg.conf.d/11-keyboard.conf

Section "InputClass"
    Identifier          "Keyboard Defaults"
    MatchIsKeyboard	"yes"
    Option	        "XkbLayout" "gb"
EndSection

The reason why the layout is "reset" is that the keyboard re-appears on the repowered usb stack, that's "normal"
Anything you did via some setxkbmap in xinitrc or so is transitional, but the xorg.conf is reapplied to every device that shows up.
Put all other keyboard specific settings there as well instead of abusing setxkbmap as static config tool.

Online

#16 2019-03-16 21:53:00

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

OK, I have done that.
But the wallpaper problem still isn't solved.  How do I make it run upon waking up?

Offline

#17 2019-03-16 22:14:48

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,586

Re: [SOLVED] Systemd errors

Did you "systemctl --user daemon-reload"?
Also try the "sleep.target" which is pulled in by various napping degrees.

Online

#18 2019-03-17 09:04:39

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Yes, I used systemctl --user daemon-reload each time I changed the unit file.
I'll try the sleep.target - but is it After or Before?

Offline

#19 2019-03-17 09:08:29

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,586

Re: [SOLVED] Systemd errors

Actually neither. Seems to be a standing issue. See
https://github.com/systemd/systemd/issu … -316647050

Online

#20 2019-03-17 09:22:20

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Nothing happened. Same results as before - not running on wake up.

[Unit]
Description=Fixes wallpaper after suspend and resets keyboard layout to UK
After=suspend.target 

[Service]
Type=oneshot
ExecStart=/usr/bin/kbd-and-background-fix

[Install]
WantedBy=multi-user.target suspend.target sleep.target

Offline

#21 2019-03-17 09:27:14

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,586

Re: [SOLVED] Systemd errors

Yes, see the link. You've to run it after the services, not the targets.

Online

#22 2019-03-17 09:29:18

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

You mean

After=suspend.target sleep.target

?

Offline

#23 2019-03-17 09:35:17

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,586

Online

#24 2019-03-17 09:56:49

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Systemd errors

I got screen locking to work after resuming from suspend (and hibernate) with this unit file:

https://forum.archlabslinux.com/t/how-t … ed/2065/45

So you don't need an After= statement or the WantedBy=multi-user.target, just add the various suspend & hibernate .targets to the WantedBy= string.

If you still have problems then perhaps try a per-user instance (as with my example) rather then a --user service (and import the DBUS_SESSION_BUS_ADDRESS globally).


Jin, Jîyan, Azadî

Offline

#25 2019-03-17 09:57:17

Vectorlocity
Member
Registered: 2018-04-15
Posts: 132

Re: [SOLVED] Systemd errors

Still doesn't work:

[Unit]
Description=Fixes wallpaper after suspend and resets keyboard layout to UK
After=sleep.service suspend.service

[Service]
Type=oneshot
ExecStart=/usr/bin/kbd-and-background-fix

[Install]
WantedBy=multi-user.target suspend.service sleep.service

Offline

Board footer

Powered by FluxBB