I have custom script to mount google drives.
Part of this script, is following code:
if [ ! "$(which google-drive-ocamlfuse)" ]
then
echo "Install google-drive-ocamlfuse first!"
exit 1
fi
Executed from terminal, works like charm.
So, I configured it as service:
[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
Unfortunately, I see exit code: "Install google-drive-ocamlfuse first!" when I checking service status.
Command which google-drive-ocamlfuse under user and root gives me valid path:
$ which google-drive-ocamlfuse
/home/<usernamehere>/.opam/default/bin/google-drive-ocamlfuse
Where is the problem?
Best Answer
The problem is that, when the script runs as a service, it does not run as "you": it does not have your environment. Specifically, it does not have your
PATH
variable.Either add
/home/<usernamehere>/.opam/default/bin
to the PATH in your script, or simply hardcode the full path for that program.