Running a script using service in Debian 10

I am running a Debian 10. That I would like to map a FTP drive on boot up. I have the .sh file that works on its own but when using the ftpconnect.service that I created. With the help of this site posts it does not do any think and shows as inactive (dead)

If I run a command the FTP Drive gets mapped and I can use it.

/mnt/ftpconnect.sh start

But I would like it to start when the system starts. Whilst checking the path to were the drive should be mapped its not connected.

I have tried enabling networ-online.target, Types=simple, User=Root, WorkingDirectory. and restart=on-failure I have redisabled them

This file below is called ftpconnect.service

[Unit]
Description=Maps FTP Bacup to /mnt folder
# After=network.target
# After=systemd-user-sessions.service
# After=network-online.target

[Service]
# User=root
# Type=simple
# PIDFile=/run/my-service.pid
# WorkingDirectory=/mnt/
ExecStart=/mnt/ftpconnect.sh start
#ExecReload=/mnt/ftpconnect.sh reload
#ExecStop=/mnt/ftpconnect.sh stop
# TimeoutSec=30
# Restart=on-failure
# RestartSec=30
# StartLimitInterval=350
# StartLimitBurst=10

[Install]
WantedBy=default.target

The .sh file is called ftpconnect.sh and is located in /mnt/ftpconnect.sh

#! /bin/sh
### BEGIN INIT INFO
# Provides:          ftpserver
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start ftpserver daemon at boot time
# Description:       Enable ftpserver service provided by daemon.
### END INIT INFO

# Author: Justin Hartman <[email protected]>
# URL: http://justinhartman.co.za
# From Debian skeleton

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/curlftpfs
OPTIONS="-o allow_other ftp://USERNAME:PASSWORD@URL" <<I HAVE REMOVED THESE DETAILS FOR SECURITY>>
MOUNT=/mnt/backupdrive
UMOUNT=/bin/umount
NAME=backupdrive
DESC="Remote FTP Server Mount"

PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

case "$1" in
  start)
        echo -n "Mounting the $DESC: $NAME"
        $DAEMON $OPTIONS $MOUNT
        echo "Server has been mounted at $MOUNT"
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        $UMOUNT $MOUNT
        echo "Server has been unmounted"
        ;;
  restart|force-reload)
        echo -n "Re-mounting the $DESC: $NAME"
        $UMOUNT $MOUNT
        sleep 2
        $DAEMON $OPTIONS $MOUNT
        echo "The server has been re-mounted at $MOUNT"
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

Could anyone help me see what I am doing wrong. As what I have been reading it all looks ok. But clearly I am doing some think wrong.


Solution 1:

Thanks to Michael Hampton. This it what worked for me and the drive now auto mounts

How I did it.

mkdir /mnt/backupdrive    
nano /etc/fstab

Added

curlftpfs#ftp://USERNAME:[email protected]/ /mnt/backupdrive fuse _netdev 0 0

Saved and rebooted the FTP Drive mounted under backupdrive after reboot.

I found that if the below was not added the system would fail due to network. I assume it was trying to run before the network had connected.

_netdev