我有一个简单的服务,可以启动一个脚本,通过以下方式安装谷歌驱动器目录GD保险丝。该脚本在从终端手动运行时有效。当使用 systemd 启动时它会失败,这似乎是我在几个小时的搜索中设置脚本在启动时运行的唯一最新方法。
这是系统服务gdrive.service
:
[Unit]
Description=Mount google drives
[Service]
ExecStart=/bin/bash /home/james/gdrive.sh
[Install]
WantedBy=multi-user.target
这是脚本:
#!/bin/bash
/usr/bin/google-drive-ocamlfuse -label mydrive /home/james/GoogleDrive/MyDrive/
/usr/bin/google-drive-ocamlfuse -label shareddrive /home/james/GoogleDrive/SharedDrive/
/usr/bin/google-drive-ocamlfuse -label shareddrive2 /home/james/GoogleDrive/SharedDrive2/
这是我尝试启动服务时的 systemctl 状态(是的,我已经运行了 systemctl daemon-reload):
× gdrive.service - Mount google drives
Loaded: loaded (/etc/systemd/system/gdrive.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2022-09-14 15:41:19 PDT; 1s ago
Process: 4997 ExecStart=/bin/bash /home/james/gdrive.sh (code=exited, status=2)
Main PID: 4997 (code=exited, status=2)
CPU: 24ms
Sep 14 15:41:19 blister systemd[1]: Started Mount google drives.
Sep 14 15:41:19 blister bash[4998]: Fatal error: exception Not_found
Sep 14 15:41:19 blister bash[4999]: Fatal error: exception Not_found
Sep 14 15:41:19 blister bash[5000]: Fatal error: exception Not_found
Sep 14 15:41:19 blister systemd[1]: gdrive.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Sep 14 15:41:19 blister systemd[1]: gdrive.service: Failed with result 'exit-code'.
我还用一个简单的脚本替换了 gdrive.shecho hello
并且它启动成功,所以我的 systemd 设置原则上可以正常运行...根据错误,似乎从 systemd 运行时,google-drive-ocamlfuse 命令没有被执行发现(尽管我用绝对路径替换了所有内容以防万一)。如果有帮助的话,我就在 Xubuntu 上。