Systemd 服务以 enable/start 命令启动,但在启动时不执行任何操作

Systemd 服务以 enable/start 命令启动,但在启动时不执行任何操作

我有一个简单的脚本,可以在启动时将键盘背光设置为 0。如果手动调用,它会起作用。而且我有应该在启动时调用它的服务。

[Unit]
Description=Power_off keyboard backlight on startup

[Service]
Type=oneshot
ExecStart=/etc/kbd_to_zero
RemainAfterExit=yes
[Install]
WantedBy=default.target

运行命令 systemctl enable now 或 start 时,此服务运行正常。但它在启动时不执行任何操作。journalctl 说

січ 24 02:05:35 dmytro-VivoBook-S15-X530UA systemd[1]: Starting Power_off keyboard backlight on startup...
січ 24 02:05:35 dmytro-VivoBook-S15-X530UA sudo[3370]: root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/tee /sys/class/leds/asus::kbd_backlight/brightness
січ 24 02:05:35 dmytro-VivoBook-S15-X530UA sudo[3370]: pam_unix(sudo:session): session opened for user root by (uid=0)
січ 24 02:05:35 dmytro-VivoBook-S15-X530UA kbd_to_zero[3364]: 0
січ 24 02:05:35 dmytro-VivoBook-S15-X530UA sudo[3370]: pam_unix(sudo:session): session closed for user root
січ 24 02:05:35 dmytro-VivoBook-S15-X530UA systemd[1]: Started Power_off keyboard backlight on startup.

我做错了什么。

谢谢

答案1

您是否尝试运行启用命令?假设您的服务名为 keyboard-backlight.service,请尝试运行以下命令:systemctl enable keyboard-backlight.service

相关内容