小编Blo*_*och的帖子

systemd 服务:权限被拒绝

我有一个新的 systemd 服务,它无法以“权限被拒绝”错误启动。我买了一台 Thinkpad L480。不幸的是,内核似乎存在未检测到触摸板的问题。这是解决here可以解决

sudo sh -c 'echo -n "elantech" > /sys/bus/serio/devices/serio1/protocol'
Run Code Online (Sandbox Code Playgroud)

因为我不想在每次启动时都这样做,所以我做了一个 systemd 服务,但它没有按预期工作。

我的 touchpad_enabler.service 是

[Unit]
Description=FooBar

[Service]
Type=oneshot
ExecStart=/usr/local/bin/enable_touchpad.sh

[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)

脚本文件很简单

#!/bin/bash

echo -n "elantech" > /sys/bus/serio/devices/serio1/protocol
Run Code Online (Sandbox Code Playgroud)

但我也用sh -c版本试过了。我通过调整权限

sudo chmod 744 /usr/local/bin/enable_touchpad.sh
sudo chmod 644 /etc/systemd/system/touchpad_enabler.service
Run Code Online (Sandbox Code Playgroud)

所以这两个文件都归root所有。然后我通过

systemctl enable enable_touchpad.sh
Run Code Online (Sandbox Code Playgroud)

当我通过 手动启动服务时systemctl start touchpad_enabler.service,它完全正常工作,触摸板也能正常工作。但是,在启动时,服务失败并在 中被列为“失败” systemctl list-units

的输出journalctl -b -u touchpad_enabler.service是:

systemd[1]: Starting Solves bug that Thinkpad L480 Touchpad is not correctly detected...
enable_touchpad.sh[516]: …
Run Code Online (Sandbox Code Playgroud)

linux services permissions systemd

11
推荐指数
1
解决办法
4万
查看次数

标签 统计

linux ×1

permissions ×1

services ×1

systemd ×1