Ubuntu systemd custom service failing with python script

随声附和 提交于 2021-02-10 06:41:22

问题


Would like to get some help with systemd daemon service in Ubuntu. I have a python script I wrote to disable the touchscreen on a Dell XPS which is more of a problem than a useful feature. The script works but I don't want to have to launch it all the time which is why the idea came to my head to write a service file and have systemd launch it for me on startup.

The issue I run into is "(code=exited, status=1/FAILURE)". This is my first time and I did a little bit of research before I tried this however, I just can't figure it out at this point. Any ideas would be much appreciated.

This is the "systemctl status disable-ts.service output:

● disable-ts.service - Disable TouchScreen
  Loaded: loaded (/etc/systemd/system/disable-ts.service; enabled; vendor 
  preset: enabled)
  Active: failed (Result: exit-code) since Sat 2019-02-23 01:31:27 PST; 
  6min ago
  Process: 2667 ExecStart=/usr/bin/python disable-ts.py 
 (code=exited,status=1/FAILURE)

 Feb 23 01:31:27 roman-XPS-15-9560 systemd[1]: disable-ts.service: Service 
 hold-off time over, schedul
 Feb 23 01:31:27 roman-XPS-15-9560 systemd[1]: disable-ts.service: 
 Scheduled restart job, restart coun
 Feb 23 01:31:27 roman-XPS-15-9560 systemd[1]: Stopped Disable TouchScreen.
 Feb 23 01:31:27 roman-XPS-15-9560 systemd[1]: disable-ts.service: Start 
 request repeated too quickly.
 Feb 23 01:31:27 roman-XPS-15-9560 systemd[1]: disable-ts.service: Failed 
 with result 'exit-code'.
 Feb 23 01:31:27 roman-XPS-15-9560 systemd[1]: Failed to start Disable 
 TouchScreen.

This is the service file itself:

[Unit]
Description=Disable TouchScreen
After=multi-user.target

[Service]
User=roman
Type=forking
WorkingDirectory=/home/roman/Python-Scripts/
ExecStart=/usr/bin/python disable-ts.py
Restart=always

[Install]
WantedBy=multi-user.target

After I created this I did run:

sudo systemctl daemon-reload
sudo systemctl enable disable-ts.service
sudo systemctl start disable-ts.service

回答1:


Ran into this exact problem myself today, almost entirely the same setup except I was using 'simple' for type, and had not specified user or workingdirectory. Adding the working directory worked for me.



来源:https://stackoverflow.com/questions/54840385/ubuntu-systemd-custom-service-failing-with-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!