Can't run start-up scripts with systemd services

General support questions
Post Reply
ccdan
Posts: 5
Joined: 2017/01/16 11:08:44

Can't run start-up scripts with systemd services

Post by ccdan » 2019/06/09 15:20:42

After reading a bit online, I understood that start-up scripts should be executed using systemd services... for example, I want to disable my touchpad using such a script that includes only one line: xinput disable 14 (the script work perfect ok when executed from command line or with double click)

I created a file myservice.service with the following content:

Code: Select all

[Unit]
Description=
After=network.target

[Service]
Type=simple 
ExecStart=/bin/bash /usr/bin/touchpadoff.sh
Restart=on-failure 

[Install]
WantedBy=multi-user.target
touchpadoff.sh only contains: xinput disable 14

after I try to start the service and run: systemctl status myservice.service -l , I get the following message:

myservice.service
Loaded: loaded (/usr/lib/systemd/system/myservice.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Sun 2019-06-09 17:59:21 EEST; 2s ago
Process: 17544 ExecStart=/bin/bash /usr/bin/touchpadoff.sh (code=exited, status=1/FAILURE)
Main PID: 17544 (code=exited, status=1/FAILURE)

Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: Unit myservice.service entered failed state.
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: myservice.service failed.
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: myservice.service holdoff time over, scheduling restart.
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: Stopped myservice.service.
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: start request repeated too quickly for myservice.service
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: Failed to start myservice.service.
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: Unit myservice.service entered failed state.
Jun 09 17:59:21 192-168-0-100.rdsnet.ro systemd[1]: myservice.service failed.

Any ideas why it doesn't work? If I add exit 0 to the touchpadoff.sh e get rid of the error, but it still doesn't turn the touchpad off (and says something about not being able to connect to x server - not sure why it would need that)

User avatar
TrevorH
Site Admin
Posts: 33221
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Can't run start-up scripts with systemd services

Post by TrevorH » 2019/06/09 15:44:47

I would suspect that you do not want Type=simple. Read man systemd.service and you'll see that simple is expected to continue to run so when your script exits, it's treated as a failure and it'll get restarted until systemd decides enough is enough and gives up. I suspect you want oneshot.
it still doesn't turn the touchpad off (and says something about not being able to connect to x server - not sure why it would need that)
Well, perhaps because you're running xinput which is an X utility so expects X to be running.

I'm suspecting that what you're trying to do cannot be a systemd unit as it needs X to be running. Perhaps you might do better to look at placing some config file in /etc/X11/xorg.conf.d. For example, I have the following file for my laptop which changes some settings for my synaptics (or clone) device

Code: Select all

Section "InputClass"
        Identifier "touchpad catchall"
        Driver "synaptics"
        MatchIsTouchpad "on"
        MatchDevicePath "/dev/input/event*"
        Option "ClickPad" "0"
        Option "FingerLow" "1"
        Option "FingerHigh" "10"
        Option "VertScrollDelta" "1000"
EndSection
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

ccdan
Posts: 5
Joined: 2017/01/16 11:08:44

Re: Can't run start-up scripts with systemd services

Post by ccdan » 2019/06/09 16:04:13

So ... systemd cannot start scripts or services after the x server starts?

Indeed, I did find some suggestions about editing xorg.conf.d , but I hoped my attempt with systemd would work, it seemd like a "general purpose" solution for start-up stuff, but I was probably wrong...

I didn't realize xinput was related to xserver, but anyway, the service doesn't work even if I try to start the service while logged in in graphical mode in kde ...

Thank you for answering!
Last edited by ccdan on 2019/06/09 16:08:13, edited 1 time in total.

User avatar
TrevorH
Site Admin
Posts: 33221
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Can't run start-up scripts with systemd services

Post by TrevorH » 2019/06/09 16:06:48

I suspect the reason it works when you run it manually is because you are in X so xinput just works. If you want to disable the touchpad altogether then I'm pretty sure there will be easier ways - perhaps by blacklisting the module that controls it, perhaps by adjusting its setting so it either behaves better or is ignored completely.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

ccdan
Posts: 5
Joined: 2017/01/16 11:08:44

Re: Can't run start-up scripts with systemd services

Post by ccdan » 2019/06/09 16:45:28

I finally put the script in Autostart - KDE Control Module (didn't know about this one) and it works just fine.

Post Reply