2

I am trying to set xinput settings on my laptop on boot so I made a script with all my settings and a basic systemd service file:

[Unit]
Description=Sets my preferred xinput settings

[Service]
ExecStart=/usr/local/bin/SCRIPTS/xinput.sh

[Install]
WantedBy=multi-user.target

I ran systemctl enable xinput-settings.service but that doesn't work, nor does systemctl start but running sudo bash /usr/local/bin/SCRIPTS/xinput.sh (the script requires root) works fine but this systemd service won't. I tried setting user to root and some other fixes I saw but nothing fixes it.

Here is the script contents:

xinput --set-prop "TPPS/2 IBM TrackPoint" 320 -0.4
exit 0

I am using Arch Linux kernel 5.6.12-arch1-1

systemctl status xinput-settings says:

● xinput-settings.service - Sets my preferred xinput settings
     Loaded: loaded (/etc/systemd/system/xinput-settings.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Fri 2020-05-15 23:34:35 +04; 42ms ago
    Process: 16809 ExecStart=/usr/local/bin/SCRIPTS/xinput.sh (code=exited, status=203/EXEC)
   Main PID: 16809 (code=exited, status=203/EXEC)

May 15 23:34:35 ThinkX250 systemd[1]: Started Sets my preferred xinput settings.
May 15 23:34:35 ThinkX250 systemd[16809]: xinput-settings.service: Failed to execute command: No such file or directory
May 15 23:34:35 ThinkX250 systemd[16809]: xinput-settings.service: Failed at step EXEC spawning /usr/local/bin/SCRIPTS/xinput.sh: No such file or directory
May 15 23:34:35 ThinkX250 systemd[1]: xinput-settings.service: Main process exited, code=exited, status=203/EXEC
May 15 23:34:35 ThinkX250 systemd[1]: xinput-settings.service: Failed with result 'exit-code'.
Xilog
  • 21
  • 1
  • 4
  • 1
    It might not work because `systemd` command does not exist. You probably wanted to use `systemctl` command instead. Also, `…enable xinput-settings.service` is not supposed to run the service right now, it enables it to run on boot. Another problem is calling `exit 0` in the end. You don't want this because you won't know if `xinput` failed for some reason *(which it well may because you use numeric ID instead of a property name in `xinput` call, and those may change)*. What does `systemctl start xinput-settings && systemctl status xinput-settings` say? – Hi-Angel May 14 '20 at 19:02
  • Although I stand corrected, [there is a binary called `systemd`](https://www.freedesktop.org/software/systemd/man/systemd.html). But it is for internal use and does not have the `enable` or `start` options. On my system it is not in $PATH too. – Hi-Angel May 14 '20 at 19:14
  • @K7AAY I am using Arch Linux kernel 5.6.12-arch1-1, will edit – Xilog May 15 '20 at 19:33
  • @Hi-Angel sorry, i meant systemctl. – Xilog May 15 '20 at 19:33
  • updated post with what systemctl status says. – Xilog May 15 '20 at 19:35
  • 2
    `xinput` will not work since it isn't specified which X server to connect to (if any would be running when the unit is ran). It would be better to either edit the [X server configuration](https://wiki.archlinux.org/index.php/Xorg#Configuration) or to run your script from your display manager – Torin May 15 '20 at 19:54
  • Regarding the error you see in `systemctl status`, try adding full path to `xinput`, which is `/usr/bin/xinput` on Archlinux. However as noted by Torin, indeed if the service will be executed before X server launched, this won't work. I.e. you may make it work right now *(e.g. by adding `DISPLAY=:0` if needed)*, but the next time you boot it gonna fail anyway. – Hi-Angel May 16 '20 at 01:09
  • Add `Environment="DISPLAY=:0"` to the `[Service]` section to specify a display, and add `After=graphical.target` to the `[Unit]` section to ensure this doesn't start up before your x-server is running. Also consider adding `Type=oneshot` and `RemainAfterExit=yes` to your `[Service]` section so that the service considers itself started for your whole session. – Stewart May 16 '20 at 08:17
  • Ah ok. Thanks. I'll try what you said. – Xilog May 16 '20 at 12:27
  • Weird, adding DISPLAY=:0 and trying to use the full path have the same error with not being able to find the file. – Xilog May 16 '20 at 12:34
  • Well KDE autostart made it work. I didn't know KDE could autostart – Xilog May 16 '20 at 12:52
  • The script does not have a shebang or executable bit set? – Vlastimil Burián May 16 '20 at 13:30

2 Answers2

1

Consider this service unit instead:

[Unit]
Description=Sets my preferred xinput settings

[Service]
Type=oneshot
ExecStart=/usr/local/bin/SCRIPTS/xinput.sh
Environment="DISPLAY=:0"
RemainAfterExit=yes

[Install]
WantedBy=graphical.target

Line by line explanation:

  • Type=oneshot is suitable for scripts which are executed once and then end. If you don't specify this, Type=simple is defaulted and systemd may be surprised that your service ended so quickly. I think that's probably the first reason why you had Active: failed
  • Environment="DISPLAY=:0". You can have several users logged in and several displays active at a time. systemd isn't attached to a desktop/display so if it runs xinput, xinput will fail. By setting this environment variable, you are telling xinput which display to use
  • RemainAfterExit=yes. Not strictly necessary, but I like this for oneshot types. It means when the service is complete its status will be active (exited) instead of inactive (dead).
  • WantedBy=graphical.target means that this service will be started after the xserver starts.

If you still have problems, it may be related to the xauthority. In that case, see a good answer here:

Setting DISPLAY in systemd service file

Stewart
  • 12,628
  • 1
  • 37
  • 80
0

Adding my script to KDE autostart worked even with sudo.

Xilog
  • 21
  • 1
  • 4