首页 > 解决方案 > 在 systemd 服务上运行 gui 应用程序时出错

问题描述

我正在尝试在 systemd 服务中运行一个 gui 命令,我希望它在系统启动时执行。

这些是我的文件。

oversteer.sh 文件:

#!/bin/bash

sleep 1s

export DISPLAY=:99.0
export SCREEN_WIDTH=1200
export SCREEN_HEIGHT=960
export SCREEN_DEPTH=24
export GEOMETRY="${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_DEPTH}"

sudo oversteer --autocenter 45 &
sudo oversteer --range 720

oversteer.service 文件:

[Unit]
Description = oversteer
After=local-fs.target

[Service]
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/ubuntu/.Xauthority"
ExecStart=/home/ubuntu/g29_steering_wheel/autostart_scripts/oversteer.sh
Restart=on-failure
Type=simple
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

我已将此文件放在 /etc/systemd/system 中,并已授予可执行权限和 root 权限。但是,该服务似乎因为没有显示而失败。

错误如下:

Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(oversteer:8052): Gdk-CRITICAL **: 08:00:50.744: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

(oversteer:8053): Gdk-CRITICAL **: 08:00:50.763: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3.py", line 45, in <module>
    cursors.MOVE          : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
TypeError: constructor returned NULL

我正在使用 ubuntu 20.04 在 raspi 4 上运行。转向过度是一个用于控制我的操纵杆参数的包。

标签: shellgtk3systemdxservergdk

解决方案


推荐阅读