我无法为运行Debian Jessie的Beaglebone上的python脚本启用systemd自动启动服务。我在我的脚本中使用Tkinter。这是我的单位文件代码:
[Unit]
Description=Startup OQY
[Service]
WorkingDirectory=/home/debian/oqy
ExecStart=/usr/bin/python oqy.py
SyslogIdentifier=oqy
[Install]
WantedBy=multi-user.target
这是状态错误
● oqy.service - Startup OQY
Loaded: loaded (/lib/systemd/system/oqy.service; enabled)
Active: failed (Result: exit-code) since Wed 2016-04-06 16:40:35 UTC; 2min 58s ago
Process: 10739 ExecStart=/usr/bin/python oqy.py (code=exited, status=1/FAILURE)
Main PID: 10739 (code=exited, status=1/FAILURE)
Apr 06 16:40:35 beaglebone oqy[10739]: Traceback (most recent call last):
Apr 06 16:40:35 beaglebone oqy[10739]: File "oqy.py", line 270, in <module>
Apr 06 16:40:35 beaglebone oqy[10739]: main()
Apr 06 16:40:35 beaglebone oqy[10739]: File "oqy.py", line 252, in main
Apr 06 16:40:35 beaglebone oqy[10739]: root = tk.Tk()
Apr 06 16:40:35 beaglebone oqy[10739]: File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
Apr 06 16:40:35 beaglebone oqy[10739]: self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
Apr 06 16:40:35 beaglebone oqy[10739]: _tkinter.TclError: no display name and no $DISPLAY environment variable
Apr 06 16:40:35 beaglebone systemd[1]: oqy.service: main process exited, code=exited, status=1/FAILURE
Apr 06 16:40:35 beaglebone systemd[1]: Unit oqy.service entered failed state.
我做错了什么?
更新:系统服务配置系统服务。 GUI必须等到显示服务器和显示管理器启动,所以我根本不应该使用systemd。
答案 0 :(得分:0)
正如我上面所写,systemd服务配置系统服务。 GUI必须等到显示服务器和显示管理器启动,因此systemd无法加载GUI。
相反,将文件写入/ etc / xdg / autostart,如下所示:
[Desktop Entry]
Type=Application
Exec=sudo /usr/bin/python /home/debian/oqy/oqy.py
Name=oqy
Comment=Startup OQY on load