1

I'm trying to get google-drive-ocamlfuse to mount on Fedora 35 Linux at startup.

I've installed opam and successfully installed google-drive-ocamlfuse.

Because this is on a laptop using WiFi to connect to the Internet, I created a bash script to run at startup, as per these instructions on the google-drive-ocamlfuse wiki:

#!/bin/bash

while true; do
  # check to see if there is a connection by pinging a Google server
  if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then
    # if connected, mount the drive and break the loop
    /home/myusername/.opam/default/bin/google-drive-ocamlfuse /home/myusername/GoogleDrive; break;
  else
    # if not connected, wait for one second and then check again
    sleep 1
  fi
done

I've placed the script in /usr/local/bin, though the blurb on the wiki does indeed say to put it in /home/username/bin. I see no reason why this would matter one way or the other.

In /etc/systemd/system, I have a systemd service I made, mount-google-drive.service that's just supposed to run the script:

[Unit]
Description=Run shell script to launch google-drive-ocamlfuse at startup

[Service]
User=myusername
Group=myusername
ExecStart=/usr/local/bin/mount-google-drive-ocamlfuse.sh

[Install]
WantedBy=multi-user.target

If I run $ /usr/local/bin/mount-google-drive-ocamlfuse.sh manually, then the Google Drive folder mounts just fine. However, I can't seem to get the systemd service to successfully run the script at startup.

I modified my ~/.bashrc file with export PATH=$PATH:$HOME/.opam/default/bin/ so as to permanently make google-drive-ocamlfuse available in my $PATH. I've run $ sudo systemctl daemon-reload, and rebooted.

/usr/local/bin/mount-google-drive-ocamlfuse.sh has permissions -rwxr-xr-x.

/etc/systemd/system/mount-google-drive.service has permissions -rwxr-xr-x.

When I run $ sudo systemctl status mount-google-drive.service, it appears that systemd has indeed run the script, but for some reason it isn't actually mounting the ~/GoogleDrive folder:

$ sudo systemctl status mount-google-drive.service 
○ mount-google-drive.service - Run shell script to launch google-drive-ocamlfuse at startup
     Loaded: loaded (/etc/systemd/system/mount-google-drive.service; enabled; vendor preset: disabled)
     Active: inactive (dead) since Sun 2021-12-05 22:36:19 CST; 2min 58s ago
    Process: 1360 ExecStart=/usr/local/bin/mount-google-drive-ocamlfuse.sh (code=exited, status=0/SUCCESS)
   Main PID: 1360 (code=exited, status=0/SUCCESS)
        CPU: 67ms

Dec 05 22:36:11 fedora systemd[1]: Started Run shell script to launch google-drive-ocamlfuse at startup.
Dec 05 22:36:11 fedora mount-google-drive-ocamlfuse.sh[1382]: ping: connect: Network is unreachable
Dec 05 22:36:12 fedora mount-google-drive-ocamlfuse.sh[1573]: ping: connect: Network is unreachable
Dec 05 22:36:13 fedora mount-google-drive-ocamlfuse.sh[1614]: ping: connect: Network is unreachable
Dec 05 22:36:14 fedora mount-google-drive-ocamlfuse.sh[1616]: ping: connect: Network is unreachable
Dec 05 22:36:15 fedora mount-google-drive-ocamlfuse.sh[1618]: ping: connect: Network is unreachable
Dec 05 22:36:16 fedora mount-google-drive-ocamlfuse.sh[1620]: ping: connect: Network is unreachable
Dec 05 22:36:17 fedora mount-google-drive-ocamlfuse.sh[1622]: ping: connect: Network is unreachable
Dec 05 22:36:19 localhost-live.lan systemd[1]: mount-google-drive.service: Deactivated successfully.

To check to make sure that myusername is actually running the script, I run $ su - myusername -c 'bash /usr/local/bin/mount-google-drive-ocamlfuse.sh' and that mounts the drive perfectly, as expected.

Why does systemd seem to run the script "successfully" but in reality it's not mounting the ~/GoogleDrive folder via google-drive-ocamlfuse as when I run the bash script manually?

user260467
  • 111
  • 3
  • 1
    You should address the network error message, `ping: connect: Network is unreachable` – roaima Dec 06 '21 at 16:13
  • @roaima That's the actual purpose of the looping bash script--waiting for WiFi to connect before attempting to mount the filesystem. – user260467 Dec 06 '21 at 16:20
  • I agree that there doesn’t seem to be a reason why it would make a difference, but have you tried placing the script in the location mentioned by the docs? – bxm Dec 06 '21 at 16:35
  • What output do you see when you run the script by hand? – bxm Dec 06 '21 at 16:37
  • @Christopher Just added some info that yes, it mounts when I run as `myusername`. I might be not understanding though--how do I know if systemd itself is not using `myusername`? – user260467 Dec 08 '21 at 02:41
  • Can you not use `After=network-online.target Wants=network-online.target` in your mount service? What am I missing? – Stephen Boston Dec 08 '21 at 03:45
  • Found your question while searching for an answer to a similar question. [This blog may help](https://medium.com/@artur.klauser/mounting-google-drive-on-raspberry-pi-f5002c7095c2) – Seamus Dec 08 '21 at 23:07

1 Answers1

0

Replace all the "~" with the full path. "~" is a $SHELL feature. E.g. mount /home/user240467/GoogleDrive rather than ~/GoogleDrive. Ensure (man mkdir) that /home/user240467/GoogleDrive exists.

You're welcome to download, use, and modify my net-o-matic script.

I've written a bash script to help with this: https://github.com/waltinator/net-o-matic It watches the connection, and when the connection drops, does a user-specified thing to try to reconnect.

waltinator
  • 4,439
  • 1
  • 16
  • 21
  • Where do you see that I'm even using `~`? I'm not. Nowhere in the shell script or the sytstemd service is that notation used. – user260467 Dec 08 '21 at 02:25
  • Would have been nice if the OP followed up on this issue. I am having a very similar problem. I'm pretty tired so this is probably more of the problem. When I figure out what resolves my issue I will post the solution in here since this guy didn't care to do anything. – waltmagic Dec 14 '22 at 06:28
  • Turns out my issue wasn't related to this question as much as I thought or I'd post an answer here. I'm pretty sure the issue the OP is having is a permissions issue. This is why the documentation he was following suggested placing the shell script under the home directory. When mounting drives outside the user permission scope sudo or root is required. I think this is what is happening. I need sleep. – waltmagic Dec 14 '22 at 07:09