8
3
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?
I don't know how your service files are configured but I suspect that the description needs to be in quotes?
Description="Mount and umount google drives"
maybe – djsmiley2k TMW – 2019-09-28T12:21:13.767Checking the redhat documentation it seems that isn't the case. And re-reading your question it can't be the issue as the script is being executed. I'm presuming for 'user' you have it set to run as your own user? If not, you need to check that the user you're running it as, has access to google-drive-ocamlfuse. This may require making sure it's on their $PATH which might be different to the $PATH you have when you login on an interactive shell. – djsmiley2k TMW – 2019-09-28T12:23:37.680
@djsmiley2k what is important: without code in first block, script working as service perfectly. – rah606 – 2019-09-28T12:26:19.150
1That's very weird, can you add
echo $PATH
to the error block, to see what path is set to at that time. – djsmiley2k TMW – 2019-09-28T12:28:35.883Note you can use the bash builtin
type
instead of calling out towhich
. – glenn jackman – 2019-09-28T12:37:21.5431As a side note, this should probably run as user systemd instance. It will assume environment of your user by default. Put it in
~/.config/systemd/user/
and run withsystemctl --user start <service>
. (Note: I believe not all distributions enable user systemd instance by default) – Mirek Długosz – 2019-09-29T09:10:52.187@MirekDługosz that could be a full answer to be honest, as it'd 'fix' the issue by setting $PATH correctly. – djsmiley2k TMW – 2019-09-29T12:43:03.030