小编rah*_*606的帖子

作为 linux-service 的 Bash 脚本不会运行,但从终端执行可以完美运行

我有自定义脚本来挂载谷歌驱动器。
此脚本的一部分是以下代码:

if [ ! "$(which google-drive-ocamlfuse)" ]
then
    echo "Install google-drive-ocamlfuse first!"
    exit 1
fi
Run Code Online (Sandbox Code Playgroud)

从终端执行,就像魅力一样。
因此,我将其配置为服务:

[Unit]
Description=Mount and umount google drives

[Service]
User=<usernamehere>
Type=oneshot
RemainAfterExit=true
ExecStart=/home/<usernamehere>/mybscripts/gdrivemounter.sh -m
ExecStop=/home/<usernamehere>/mybscripts/gdrivemounter.sh -u
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/<usernamehere>/.Xauthority"

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

不幸的是,我看到退出代码:“首先安装 google-drive-ocamlfuse!” 当我检查服务状态时。

命令which google-drive-ocamlfuse在用户和 root 下为我提供了有效路径:

$ which google-drive-ocamlfuse
/home/<usernamehere>/.opam/default/bin/google-drive-ocamlfuse
Run Code Online (Sandbox Code Playgroud)

问题出在哪儿?

services bash daemon autostart

8
推荐指数
1
解决办法
1539
查看次数

标签 统计

autostart ×1

bash ×1

daemon ×1

services ×1