티스토리 뷰

도커 컨테이너 프로세스를 체크하여, 재시작하는 스크립트 작성

1. 파일명
- DockerPsCheck.sh 

#!/bin/bash

PROC_ID=$(docker ps | grep mongo)

if [ -n "${PROC_ID}" ];
then
 echo "ALIVE : ${PROC_ID}"
else
 echo "DEAD : Restart!"
 docker start [CONTAINER ID]
fi


2. 배치등록
# Docker Container Check
*/15 * * * * /home/batch/DockerPsCheck.sh > /home/batch/log/DockerPsCheck.log

 

 

- 옵션

! EXPRESSION The EXPRESSION is false.
-n STRING The length of STRING is greater than zero.
-z STRING The lengh of STRING is zero (ie it is empty).
STRING1 = STRING2 STRING1 is equal to STRING2
STRING1 != STRING2 STRING1 is not equal to STRING2
INTEGER1 -eq INTEGER2 INTEGER1 is numerically equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is numerically greater than INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is numerically less than INTEGER2
-d FILE FILE exists and is a directory.
-e FILE FILE exists.
-r FILE FILE exists and the read permission is granted.
-s FILE FILE exists and it's size is greater than zero (ie. it is not empty).
-w FILE FILE exists and the write permission is granted.
-x FILE FILE exists and the execute permission is granted.

 

* 출처 : ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php#test

 

댓글