用于禁用设备的systemd服务无法启动

时间:2016-02-23 20:09:54

标签: ubuntu systemd xinput

我编写了用于禁用笔记本电脑lenovo x230平板电脑手指触摸的脚本。我想在启动时运行它,所以我使用systemd服务在启动时触发此脚本,但是我甚至无法手动启动此脚本。有什么帮助吗?

脚本

[Unit]
Description=Turn-off finger touch

[Service]
Type=oneshot
ExecStart=/bin/sh -c "xinput set-prop 'Wacom ISDv4 E6 Finger touch' 'Device Enabled' 0"

[Install]
WantedBy=multi-user.target

以下是此服务的状态命令输出

systemctl status finger-touch-off.service
● finger-touch-off.service - Turn-off finger touch
Loaded: loaded (/etc/systemd/system/finger-touch-off.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Ut 2016-02-23 21:03:46 CET; 6s ago
Process: 2992 ExecStart=/bin/sh -c xinput set-prop 'Wacom ISDv4 E6 Finger touch' 'Device Enabled' 0 (code=exited, status=1/FAILURE)
Main PID: 2992 (code=exited, status=1/FAILURE)

feb 23 21:03:46 xxx-thinktablet systemd[1]: Starting Turn-off finger touch...
feb 23 21:03:46 xxx-thinktablet sh[2992]: Unable to connect to X server
feb 23 21:03:46 xxx-thinktablet systemd[1]: finger-touch-off.service: main process exited, code=exited, status=1/FAILURE
feb 23 21:03:46 xxx-thinktablet systemd[1]: Failed to start Turn-off finger touch.
feb 23 21:03:46 xxx-thinktablet systemd[1]: Unit finger-touch-off.service entered failed state.
feb 23 21:03:46 xxx-thinktablet systemd[1]: finger-touch-off.service failed.

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。您必须在执行xinput之前执行此操作:

export DISPLAY=:0.0

systemd脚本将是:

[Unit]
Description=Turn-off finger touch

[Service]
Type=oneshot
ExecStart=/bin/sh -c "export DISPLAY=:0.0 && xinput set-prop 'Wacom ISDv4 E6 Finger touch' 'Device Enabled' 0"

[Install]
WantedBy=multi-user.target