Ejecutar un script usando el servicio en Debian 10

Ejecutar un script usando el servicio en Debian 10

Estoy ejecutando Debian 10. Me gustaría asignar una unidad FTP al arrancar. Tengo el archivo .sh que funciona por sí solo pero cuando uso el servicio ftpconnect.service que creé. Con la ayuda de las publicaciones de este sitio, no piensa y se muestra como inactivo (muerto).

Si ejecuto un comando, la unidad FTP se asigna y puedo usarla.

/mnt/ftpconnect.sh start

Pero me gustaría que se iniciara cuando se inicie el sistema. Mientras verifica la ruta hacia donde se debe asignar la unidad, no está conectada.

Intenté habilitar networ-online.target, Types=simple, User=Root, WorkingDirectory. y reiniciar = en caso de falla, los he vuelto a desactivar

El siguiente archivo se llama 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

El archivo .sh se llama ftpconnect.sh y se encuentra en /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

¿Alguien podría ayudarme a ver qué estoy haciendo mal? Según lo que he estado leyendo, todo parece estar bien. Pero claramente estoy pensando mal.

Respuesta1

Gracias a Michael Hampton. Esto es lo que funcionó para mí y la unidad ahora se monta automáticamente.

Cómo lo hice.

mkdir /mnt/backupdrive    
nano /etc/fstab

Agregado

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

Guardé y reinicié la unidad FTP montada en la unidad de respaldo después del reinicio.

Descubrí que si no se agregaba lo siguiente, el sistema fallaría debido a la red. Supongo que estaba intentando ejecutarse antes de que se conectara la red.

_netdev

información relacionada