我正在运行 Debian 10。我想在启动时映射 FTP 驱动器。我有一个可以独立运行的 .sh 文件,但使用我创建的 ftpconnect.service 时。在本网站帖子的帮助下,它没有任何反应,并显示为不活动(死机)
如果我运行命令,FTP 驱动器就会被映射,我就可以使用它。
/mnt/ftpconnect.sh start
但我希望它在系统启动时启动。在检查驱动器应映射的路径时,发现它未连接。
我尝试启用 networ-online.target、Types=simple、User=Root、WorkingDirectory。并且 restart=on-failure 我已经重新禁用它们
下面这个文件名为 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
.sh 文件名为 ftpconnect.sh,位于 /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
有人能帮我看看我做错了什么吗?正如我所读到的,一切看起来都很好。但显然我做错了一些事情。
答案1
感谢 Michael Hampton。这个方法对我有用,现在驱动器可以自动安装
我是如何做到的。
mkdir /mnt/backupdrive
nano /etc/fstab
添加
curlftpfs#ftp://USERNAME:[email protected]/ /mnt/backupdrive fuse _netdev 0 0
保存并重新启动在重启后安装在备份驱动器下的 FTP 驱动器。
我发现,如果不添加以下内容,系统会因网络故障而失败。我猜想它是在网络连接之前尝试运行的。
_netdev