在Ubuntu上设置FTP服务器(如vsftpd)自动重启,可以通过以下几种方法实现:
安装vsftpd(如果尚未安装):
sudo apt update
sudo apt install vsftpd
启用并启动vsftpd服务:
sudo systemctl enable vsftpd
sudo systemctl start vsftpd
设置服务自动重启:
systemd默认会在系统启动时自动启动服务,并且在服务崩溃时自动重启。你可以通过以下命令查看服务的状态和配置:
sudo systemctl status vsftpd
sudo systemctl edit --full vsftpd
在编辑器中,你可以添加或修改以下内容来确保服务在崩溃时自动重启:
[Service]
Restart=always
RestartSec=5
保存并退出编辑器。
如果你不想使用systemd,可以使用cron任务来定期检查并重启FTP服务器。
编辑crontab文件:
crontab -e
添加以下行:
* * * * * /usr/sbin/service vsftpd restart
这行代码表示每分钟检查一次并重启vsftpd服务。你可以根据需要调整时间间隔。
保存并退出编辑器。
supervisord是一个进程控制系统,可以用来管理和监控多个进程。
安装supervisord:
sudo apt update
sudo apt install supervisor
配置supervisord:
编辑/etc/supervisor/conf.d/vsftpd.conf文件,添加以下内容:
[program:vsftpd]
command=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
autostart=true
autorestart=true
stderr_logfile=/var/log/vsftpd.err.log
stdout_logfile=/var/log/vsftpd.out.log
更新supervisord配置并启动服务:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start vsftpd
通过以上方法之一,你可以确保Ubuntu上的FTP服务器在系统启动时自动启动,并在服务崩溃时自动重启。选择哪种方法取决于你的具体需求和偏好。