Permanent Wacom configuration systemd udev service not running at start

Hi there !

I followed that article on the arch linux wiki to have my configuration of my cintiq wacom tablet be permanent.

According to the article, I created the udev rule which calls a “wacom.service” that runs a script wacom-config.sh

The script works and I can

systemctl --user start wacom.service

My wacom (the area) is then configured correctly.
But I still have to do that everytime I start a session !
It just doesn’t autostart and if I try to enable it with :

systemctl --user enable wacom.service

I get :

Failed to enable unit: Unit file /home/greg/.config/systemd/user/graphical-session.target.wants/wacom.service does not exist.

I don’t understand why it’s looking into a “graphical-session.target.wants” folder and if I create that folder and put my wacom.service into it I get :

Failed to enable unit: File /home/greg/.config/systemd/user/graphical-session.target.wants/wacom.service already exists.

Any idea ?
Thank you very much

should that file not be here:
~/.config/systemd/user/wacom.service

instead where it appears to be now:
~/.config/systemd/user/graphical-session.target.wants/wacom.service

Try replacing the [Install] section with:

[Install]
WantedBy=default.target

If that fails also, you could try the below command, without enabling but after staring that service, to see which targets are mentioned:

systemctl --user list-dependencies wacom

PS: The udev rule makes it un-needed to enable it because it should already start when you login into you GUI…

Besides it might not hurt to have these in your [Unit] section also:

ConditionEnvironment=DISPLAY
ConditionEnvironment=XAUTHORITY

The above will prevent it from being started when not in a GUI…

:point_up:

Thanks @TriMoon .
Here is the output of systemctl --user list-dependencies wacom

wacom.service
● ├─app.slice
● └─basic.target
●   ├─paths.target
●   ├─sockets.target
●   │ ├─dbus.socket
●   │ ├─dirmngr.socket
●   │ ├─gcr-ssh-agent.socket
●   │ ├─gnome-keyring-daemon.socket
●   │ ├─gpg-agent-browser.socket
●   │ ├─gpg-agent-extra.socket
●   │ ├─gpg-agent-ssh.socket
●   │ ├─gpg-agent.socket
●   │ ├─p11-kit-server.socket
●   │ ├─pipewire.socket
●   │ └─pulseaudio.socket
●   └─timers.target

I just restarted my computer and the wacom-config.sh did not run… I still have to manually start the service. And when I try to enable the service I still get the same message as per my 1st post

Here are my files :
image
the service :
image
the udev :

Try commenting out the graphical-session.target lines.

Exactly…

@GregDurr , those After= and PartOf= lines need to be removed or commented out because they are not mentioned in your output of list-dependencies

Anytime you make changes to a user unit’s config file, you need to let systemd know about it like you would for system units by performing:

systemctl --user daemon-reload

Only after that you can try to start it again with the changes made…
If you had done that, you could not have gotten the same error message as in first post…


Edit:
Uhmmm wait maybe you could have… due to default.target :thinking:

PS:
Next time post code as code bewteen code-blocks instead of images, so ppl can quote the part if needed or copy to try self…

PPS:
I would also suggest you to place your script at /home/greg/bin/wacom-config.sh and use that path instead, because it is a program and not a config file :wink:

ExecStart=%h/bin/wacom-config.sh

General disclaimer:

I never used user-services myself as i haven’t had any need for them…
:vulcan_salute:

Thanks @TriMoon and @dmt for your reply and advice.
It still does not run the script when I start my computer/session

systemctl --user enable wacom.service

returns

Failed to enable unit: Unit file /home/greg/.config/systemd/user/default.target.wants/wacom.service does not exist.

Wow… was not expecting it to be that difficult to run a simple script on logon !

my files :
wacom-config.sh

#!/bin/sh

for i in $(seq 10); do
    if xsetwacom list devices | grep -q Wacom; then
        break
    fi
    sleep 10
done

list=$(xsetwacom list devices)
pad=$(echo "${list}" | awk '/pad/{print $7}')
stylus=$(echo "${list}" | xsetwacom list devices | awk '/stylus/{print $7}')

if [ -z "${pad}" ]; then
    exit 0
fi

# configure the buttons on ${stylus} with your xsetwacom commands...
#xsetwacom set "${stylus}" Button 2 11
#...
xsetwacom set "${stylus}" Area 200 300 86400 65300
xsetwacom set "${stylus}" MapToOutput HEAD-0

wacom.service :

[Unit]
Description=Configure my Wacom tablet
ConditionEnvironment=DISPLAY
ConditionEnvironment=XAUTHORITY

[Service]
Type=oneshot
ExecStart=/home/greg/.config/wacom-config.sh

[Install]
WantedBy=default.target

Is there a simpler way to run a script at logon ??

Try creating ~/.config/systemd or ~/.config/systemd/user.

https://bbs.archlinux.org/viewtopic.php?id=267361

When i do: (as normal user, NOT root)

mkdir -p ~/.config/systemd/user ~/bin

Then place these files at:

  • ~/.config/systemd/user/wacom.service:

    [Unit]
    Description=Configure my Wacom tablet
    Documentation=https://wiki.archlinux.org/title/Systemd/User#Writing_user_units
    Documentation=man:systemd.special(7)"#Units managed by the user service manage"
    Documentation=man:systemd.unit(5)"#Specifiers"
    
    ConditionEnvironment=DISPLAY
    ConditionEnvironment=XAUTHORITY
    BindsTo=graphical-session.target
    
    [Service]
    Type=oneshot
    ExecStart=%h/bin/%N-config.sh
    
    [Install]
    WantedBy=xdg-desktop-autostart.target
    
  • I just created a different content to test, but you can use your script’s contents…
    ~/bin/wacom-config.sh:

    #!/usr/bin/env bash
    
    printf "%s\n" \
    	"Hello from wacom config." \
    	"DISPLAY=$DISPLAY" \
    	"XAUTHORITY=$XAUTHORITY"
    

Then i perform:

chmod a+x ~/bin/wacom-config.sh
systemctl --user daemon-reload
systemctl --user enable --now wacom

I get:

Created symlink /home/myusername/.config/systemd/user/xdg-desktop-autostart.target.wants/wacom.service → /home/myusername/.config/systemd/user/wacom.service.
  • systemctl --user status wacom
○ wacom.service - Configure my Wacom tablet
     Loaded: loaded (/home/myusername/.config/systemd/user/wacom.service; enabled; preset: enabled)
     Active: inactive (dead) since Sat 2023-01-14 12:04:27 +03; 1min 42s ago
       Docs: https://wiki.archlinux.org/title/Systemd/User#Writing_user_units
             man:systemd.special(7)#Units managed by the user service manage
             man:systemd.unit(5)#Specifiers
    Process: 3927 ExecStart=/home/myusername/bin/wacom-config.sh (code=exited, status=0/SUCCESS)
   Main PID: 3927 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Jan 14 12:04:27 kubuntu systemd[1358]: Starting Configure my Wacom tablet...
Jan 14 12:04:27 kubuntu wacom-config.sh[3927]: Hello from wacom config.
Jan 14 12:04:27 kubuntu wacom-config.sh[3927]: DISPLAY=:0
Jan 14 12:04:27 kubuntu wacom-config.sh[3927]: XAUTHORITY=/home/myusername/.Xauthority
Jan 14 12:04:27 kubuntu systemd[1358]: Finished Configure my Wacom tablet.

Logging out and back into the GUI and checking the status again shows it was started again, which you can check by the timestamp.
:vulcan_salute:


PS: I didn’t use any udev config like you posted, because i don’t actually have a wacom device…

But it should be doable to add a dependency on the device path, that gets created when you insert the device, to automatically start the service without an udev config…
(Hint: under the Install section)

Thanks a lot for your time helping me out here @TriMoon

I followed your recommendations and, as usual, when I do

systemctl --user enable --now wacom

I get

Failed to enable unit: Unit file /home/greg/.config/systemd/user/xdg-desktop-autostart.target.wants/wacom.service does not exist.

I still have to manually start the service for the script to be run…
It seems the symLink is not being created.

I think I just found another way …
I start “Session and startup” → Application Autostart and I add the wacom-setting.sh to the list to start on login. I just tried and it works.
What do you think ? Is that a valid answer to what I asked since I mentionned “udev” and “service” ?

If you are still getting that error you have/did something wrong, or skipped some steps i provided…
Can you provide the output of:

ls -la ~/.config/systemd/user ~/bin

Because i tested on my system and provided proof of it’s proper functionality to enable…

Hmm I think I followed your instructions carefullly but here is the output of

ls -la ~/.config/systemd/user ~/bin
/home/greg/bin:
total 12
drwxr-xr-x  2 greg greg 4096 15 janv. 00:22 .
drwx------ 30 greg greg 4096 15 janv. 17:46 ..
-rwxr-xr-x  1 greg greg  536 15 janv. 00:22 wacom-config.sh

/home/greg/.config/systemd/user:
total 12
drwxr-xr-x 2 root root 4096 14 janv. 23:47 .
drwxr-xr-x 3 root root 4096 11 janv. 14:23 ..
-rw-r--r-- 1 root root  448 14 janv. 23:47 wacom.service

Ok sorry I just saw that root was the owner of systemd …
I changed it to me (the user) and it did create the symlink

The script still doesn’t run at logon though…

To properly fix that you should do:

sudo chown --changes --recursive $(id -u):$(id -g) ~/.config

Which should fix possible other dirs/files under it also…
(It will output the ones it changes)

  • Maybe followed by this, but i doubt this is really needed:
    sudo chmod --changes --recursive g+rX ~/.config
    

Isn’t XFCE using systemd and XDG specs? :thinking:
Maybe it will fix itself after the above command(s)…

  • man systemd.special

    xdg-desktop-autostart.target
    The XDG specification defines a way to autostart applications using XDG desktop files. systemd ships systemd-xdg-autostart-generator(8) for the XDG desktop files in autostart
    directories. Desktop Environments can opt-in to use this service by adding a Wants= dependency on xdg-desktop-autostart.target.

No idea how to check if XFCE has indeed “opt-in” into this feature or not, as i don’t use XFCE…
But maybe this could shed a light: :thinking:

systemctl list-dependencies --user --reverse --all graphical-session{,-pre}.target

Which should mention both the xdg-desktop-autostart.target and your service, when things works like on my system with KDE…

This means your home dir can only be accessed by your user account and nothing else…
systemd needs to be able to walk into your home dir before it can find, to read and react to, the config for it self…
That should also be fixed i think… (but I’m not sure)
(Check my previous reply first to make sure everything is in order that way, before trying to fix this…)

But if that is a concern you could, especially with this service which any user on your system might benefit from, place the service and script in the global space instead.

  • /etc/systemd/user
    For the service itself.
  • /usr/local/bin
    For the script…
    Ofcourse with accompaning changes in the ExecStart line in the service :wink:

I did that, restarted and the script did not run.

I enter :

systemctl list-dependencies --user --reverse --all graphical-session{,-pre}.target

That gives me :

graphical-session.target
○ └─wacom.service
●   ├─sys-devices-pci0000:00-0000:00:1d.2-usb8-8\x2d2-8\x2d2:1.0.device
●   └─sys-devices-pci0000:00-0000:00:1d.2-usb8-8\x2d2.device

graphical-session-pre.target

Again,

ls -la ~/.config/systemd/user ~/bin

gives :

/home/greg/bin:
total 12
drwxr-xr-x  2 greg greg 4096 15 janv. 00:22 .
drwx------ 30 greg greg 4096 16 janv. 13:02 ..
-rwxr-xr-x  1 greg greg  536 15 janv. 00:22 wacom-config.sh

/home/greg/.config/systemd/user:
total 16
drwxr-xr-x 3 greg greg 4096 15 janv. 21:45 .
drwxr-xr-x 3 greg greg 4096 11 janv. 14:23 ..
-rw-r--r-- 1 greg greg  448 14 janv. 23:47 wacom.service
drwxr-xr-x 2 greg greg 4096 15 janv. 21:45 xdg-desktop-autostart.target.wants

At least now the file/dir permissions are correct. :+1:
I’ve been searching on the internet for quite some time since yesterday, but i didn’t find any info on how to “opt-in” as mentioned for XFCE…
(I don’t know either as i dont use XFCE, else i might find a way myself)

There are plenty of pages using autostart via XDG specs, that use “*.desktop” files, but not for using systemd-user-services. :woman_shrugging:


Well seems on your setup xdg-desktop-autostart.target is not mentioned :woman_shrugging:
For comparison with mine using KDE and my-user-test.service instead of your wacom.service:

graphical-session.target
○ ├─my-user-test.service
● │ └─xdg-desktop-autostart.target
● │   └─plasma-workspace.target
● │     └─plasma-workspace-x11.target
● └─plasma-workspace.target
●   └─plasma-workspace-x11.target

graphical-session-pre.target
● └─plasma-core.target
○   ├─plasma-ksplash-ready.service
●   │ ├─graphical-session.target
○   │ │ ├─my-user-test.service
●   │ │ │ └─xdg-desktop-autostart.target
●   │ │ │   └─plasma-workspace.target
●   │ │ │     └─plasma-workspace-x11.target
●   │ │ └─plasma-workspace.target
●   │ │   └─plasma-workspace-x11.target
●   │ └─plasma-workspace.target
●   │   └─plasma-workspace-x11.target
●   └─plasma-workspace.target
●     └─plasma-workspace-x11.target

But in your case graphical-session.target is still mentioned so mybe try to disable your service first, then change the service to have:

[Install]
WantedBy=graphical-session.target

Then do a daemon-reload followed by an enable again, and try if it does work this time…
There is nothing more i could help with, because theres only so much i can do while using a totally different system as yours (KDE vs XFCE and Kubuntu vs Manjaro) :woman_shrugging:
:vulcan_salute:

PS:
It looks to me like XFCE is lacking proper integration with systemd…

PPS:
Oh by the way now that all file/dir permissions are correct you might also try what i said at start of thread :rofl: