定时检查自动重启容器脚本

Posted petersonx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了定时检查自动重启容器脚本相关的知识,希望对你有一定的参考价值。

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 "33[32m The Container ID=$ID restart successfully ! 33[0m"
        else
                echo -e "33[31m The Container ID=$ID restart Failed !!!33[0m"
        fi
else
        echo -e "33[31m The Container ID=$ID is Running, No need to restart !33[0m"
fi

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

以上是关于定时检查自动重启容器脚本的主要内容,如果未能解决你的问题,请参考以下文章