要设置Linux FTP服务器(如vsftpd)自动重启,您可以使用以下方法之一:
方法1:使用systemd(适用于Systemd初始化系统)
sudo nano /etc/systemd/system/vsftpd.service
[Unit]
Description=vsftpd FTP Server
After=network.target
[Service]
Type=simple
User=ftpuser
Group=ftpuser
ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
请确保将User
和Group
设置为运行FTP服务器的用户和组。您还需要根据您的系统路径和配置文件位置调整ExecStart
和ExecReload
。
保存并关闭文件。
重新加载systemd配置:
sudo systemctl daemon-reload
sudo systemctl enable vsftpd
sudo systemctl start vsftpd
现在,vsftpd服务将在系统启动时自动运行,并在发生故障时自动重启。
方法2:使用cron(适用于SysVinit初始化系统)
打开终端。
输入以下命令以编辑root用户的crontab文件:
sudo crontab -e
@reboot /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
请确保根据您的系统路径和配置文件位置调整命令。
现在,每次系统启动时,vsftpd服务都将自动运行。如果需要,您还可以使用systemctl restart vsftpd
命令手动重启服务。