1.健康检查脚本:health.sh
#!/bin/bash
datestr=`date "+%Y-%m-%d %H:%M:%S"`
echo "$datestr : check start"
curl -s localhost:8983/solr > /dev/null
[ $? -eq 0 ] && echo "$datestr : server is running"
[ $? -ne 0 ] && echo "$datestr : server is not running, restart" && /var/www/file/images2/solr/solr-8.5.0/bin/solr restart -force -m 4g
解释,如果curl运行不成功,则运行&&后的脚本
2.crontab,每分钟检查一次,重启服务器后crontab也会自动重启,仍然每分钟检查
[root@solr]# crontab -e
## 检查solr服务,自动重启
*/1 * * * * nohup sh /var/www/file/images2/solr/health.sh 1>>"/var/www/file/images2/solr/logs/health.log" 2>&1 </dev/null &
解释:编辑crontab,每分钟执行健康检查脚本,叠加输出日志到health.log