Regularly check script automatically restart the container

vim restart.sh

 
 
#!/bin/bash

# set container ID
ID=4402f2ddc9dd

# check container running status
docker ps -a |grep -i exited 2>&1 >/dev/null

# restart container
if [ $? -eq 0 ];then
        docker restart $ID 2>&1 >/dev/null
        if [ $? -eq 0  ];then
                echo -e "\033[32m The Container ID=$ID restart successfully ! \033[0m"
        else
                echo -e "\033[31m The Container ID=$ID restart Failed !!!\033[0m"
        fi
else
        echo -e "\033[31m The Container ID=$ID is Running, No need to restart !\033[0m"
fi

crontab -u root -e
5 * * * * sh /data/nginx/restart.sh

Guess you like

Origin www.cnblogs.com/petersonx/p/12039104.html