在 Ubuntu 中,syslog 本身不负责“重启进程”,它只是记录日志。但你可能是想问以下几种情况之一,我分别说明:
Ubuntu 默认使用 rsyslog:
sudo systemctl restart rsyslog
查看状态:
sudo systemctl status rsyslog
如果你是想:当 syslog 中出现某种错误时,自动重启某个进程,常见做法有:
如果是 systemd 管理的服务:
sudo systemctl edit your-service
添加:
[Service]
Restart=on-failure
RestartSec=5
这样进程崩溃后会自动重启。
例如用 swatch:
sudo apt install swatch
配置监控 /var/log/syslog:
watchfor /ERROR/
exec "systemctl restart your-service"
#!/bin/bash
if grep -q "FATAL" /var/log/syslog; then
systemctl restart your-service
fi
加入 crontab:
* * * * * /path/to/check.sh
如果是普通进程(非 systemd):
sudo apt install supervisor
配置 /etc/supervisor/conf.d/your.conf:
[program:your-app]
command=/path/to/app
autostart=true
autorestart=true
你可以告诉我:
我可以直接给你可复制的配置。