You are not logged in.
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 UKThe 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.targetThe 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 gbWhat is wrong with my script?
Last edited by Vectorlocity (2019-03-17 17:45:56)
Offline
Isn't this an XY-problem?
To set the keyboard in X use localectl(1) (or an Xorg configuration file).
But anyway:
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.
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 ![]()
[1] ![]()
Jin, Jîyan, Azadî
Offline
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 abstractEnable 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
[1]
OK I will try ![]()
Offline
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 directoryRebooting 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
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.
DBUS_SESSION_BUS_ADDRESS seems to be set correctly.
Did you try
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESSas suggested by the StackExchange thread to which I linked?
Jin, Jîyan, Azadî
Offline
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 directoryEnable 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_ADDRESSas 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
. I just need to test it now.
Last edited by Vectorlocity (2019-03-16 19:46:02)
Offline
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 directoryEnable 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_ADDRESSas 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
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
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
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?
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
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
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
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.serviceAnd I'm a bit lost now, can we please see
systemctl --user cat kbd-and-background-fix.service --no-pThe working unit file may be useful for others experiencing this problem.
Jin, Jîyan, Azadî
Offline
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.targetOffline
Please stop this nonsense and add /etc/X11/xorg.conf.d/11-keyboard.conf
Section "InputClass"
Identifier "Keyboard Defaults"
MatchIsKeyboard "yes"
Option "XkbLayout" "gb"
EndSectionThe 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.
Offline
OK, I have done that.
But the wallpaper problem still isn't solved. How do I make it run upon waking up?
Offline
Did you "systemctl --user daemon-reload"?
Also try the "sleep.target" which is pulled in by various napping degrees.
Offline
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
Actually neither. Seems to be a standing issue. See
https://github.com/systemd/systemd/issu … -316647050
Offline
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.targetOffline
Yes, see the link. You've to run it after the services, not the targets.
Offline
You mean
After=suspend.target sleep.target?
Offline
No.
Offline
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
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.serviceOffline