[리눅스] 웹서버 상태 확인 후 자동 재시작 쉘 스크립트

- 02-28
- 41,346 회
- 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
로그인 후 댓글내용을 입력해주세요