Mount external disk via curlftps as a service
If I have an external drive I access via FTPS, how can I add a systemctl service to mount it and unmount it and have it mount it upon start-up? I already saw some examples with scripts and crontab but I found them too incoherent and hard to deal with.
Solution 1:
Create the directory where you'd like to mount the drive
mkdir /mnt/ftp-drive
Create now the file /etc/systemd/system/external-ftp.service
with this content (your systemd/system
dir might be in a different location):
[Unit]
Description=Mount FTP Space
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/curlftpfs -o ssl,no_verify_peer,nonempty,user=<user>:<pass> <host> /mnt/ftp-drive/ -f -v
ExecStop=/bin/fusermount -u /mnt/ftp-drive
[Install]
WantedBy=multi-user.target
Note the -f
option to make curlftps
run as daemon. ExecStart
and ExecStop
need full path of commands, that is, note the full path of curlftps
and fusermount
. In your case may be different, find the full path with sudo find / -name curlftps -type f
.
Now you just start the service
sudo service external-ftp start
if everything is OK, you should be able to access /mnt/ftp-drive
and the command sudo service external-ftp status
should return OK.
If everything is OK, activate the service to start on boot:
sudo systemctl enable external-ftp