Shell script runs manually, but doesn't behave as expected when started by systemd
1
vote
1
answer
791
views
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: ping: connect: Network is unreachable
Dec 05 22:36:12 fedora mount-google-drive-ocamlfuse.sh: ping: connect: Network is unreachable
Dec 05 22:36:13 fedora mount-google-drive-ocamlfuse.sh: ping: connect: Network is unreachable
Dec 05 22:36:14 fedora mount-google-drive-ocamlfuse.sh: ping: connect: Network is unreachable
Dec 05 22:36:15 fedora mount-google-drive-ocamlfuse.sh: ping: connect: Network is unreachable
Dec 05 22:36:16 fedora mount-google-drive-ocamlfuse.sh: ping: connect: Network is unreachable
Dec 05 22:36:17 fedora mount-google-drive-ocamlfuse.sh: 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?
Asked by user260467
(111 rep)
Dec 6, 2021, 03:43 PM
Last activity: Dec 8, 2021, 02:45 AM
Last activity: Dec 8, 2021, 02:45 AM