diff --git a/Dockerfile b/Dockerfile index 2ab4512..fcc2f33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM rackspacedot/python37:latest RUN apt-get update -y RUN apt-get install git -y +RUN apt-get install psmisc -y +RUN apt-get install bc -y RUN rm -rf /etc/localtime RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN cd /root \ diff --git a/README.md b/README.md index 6e525f1..f154b94 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ docker pull redis # 创建 entrypoint.sh 入口文件 echo '#! /bin/sh \ cd /root/word_cloud_bot && python3 main.py >> output 2>&1 & +cd /root/word_cloud_bot && bash restart.sh 2>&1 & tail -f /dev/null' > /root/entrypoint.sh # 创建 Dockerfile diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2841ae4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#! /bin/sh \ +cd /root/word_cloud_bot && python3 main.py >> output 2>&1 & +cd /root/word_cloud_bot && bash restart.sh 2>&1 & +tail -f /dev/null \ No newline at end of file diff --git a/restart.sh b/restart.sh new file mode 100644 index 0000000..09b1238 --- /dev/null +++ b/restart.sh @@ -0,0 +1,19 @@ +#/bin/bash +#environment variable +source /etc/profile +#memory +while : +do + bu=`free | awk 'NR==2{print $6}'` + ca=`free | awk 'NR==2{print $7}'` + us=`free | awk 'NR==2{print $3}'` + to=`free | awk 'NR==2{print $2}'` + mem=`expr "scale=2;($us-$bu-$ca)/$to" |bc -l | cut -d. -f2` + if(($mem >= 10)) + then + echo "restart" + killall -9 python3 + cd /root/word_cloud_bot && python3 main.py >> output 2>&1 & +fi + sleep 10 +done \ No newline at end of file