웹서버 상태 확인 후 자동 재시작 쉘 스크립트
-
오길호
- 02-28
- 43,898 회
- 0
- ServerMonitor.sh 파일 생성
#!/bin/bash
status=$(curl -s -o /dev/null -w "%{http_code}" localhost)
if [ $status -eq 502 ]; then
systemctl restart php-fpm.service
elif [ $status -ne 200 ]; then
systemctl restart httpd.service
fi
- ServerMonitor.sh 권한 설정
chmod 700 ServerMonitor.sh
- cron 에 등록하여 1분마다 상태 확인
crontab -e
* * * * * /root/ServerMonitor.sh >& /dev/null
- cron 재시작
systemctl restart crond.service