问题描述
想在Ubuntu中获得有关systemd守护程序服务的帮助.我有一个编写的Python脚本来禁用Dell XPS上的触摸屏,这更多的是问题而不是有用的功能.该脚本有效,但是我不想一直启动它,这就是为什么我想到编写服务文件并在启动时系统地为我启动它的原因.
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.
我遇到的问题是(代码=已退出,状态= 1/失败)".这是我的第一次,在尝试此操作之前我做了一些研究,但是,我现在还无法弄清楚.任何想法将不胜感激.
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.
这是"systemctl status disable-ts.service输出:
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.
这是服务文件本身:
[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
推荐答案
今天我自己遇到了这个确切的问题,几乎完全相同的设置,除了我使用'simple'作为类型,并且未指定用户或工作目录.添加工作目录对我有用.
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.
这篇关于Ubuntu Systemd自定义服务因python脚本而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!