自动重启

This commit is contained in:
机器人总动员 2021-05-09 11:14:12 +08:00
parent c167106d15
commit 3e797c46ec
4 changed files with 26 additions and 0 deletions

View File

@ -1,6 +1,8 @@
FROM rackspacedot/python37:latest FROM rackspacedot/python37:latest
RUN apt-get update -y RUN apt-get update -y
RUN apt-get install git -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 rm -rf /etc/localtime
RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN cd /root \ RUN cd /root \

View File

@ -27,6 +27,7 @@ docker pull redis
# 创建 entrypoint.sh 入口文件 # 创建 entrypoint.sh 入口文件
echo '#! /bin/sh \ echo '#! /bin/sh \
cd /root/word_cloud_bot && python3 main.py >> output 2>&1 & 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 tail -f /dev/null' > /root/entrypoint.sh
# 创建 Dockerfile # 创建 Dockerfile

4
entrypoint.sh Normal file
View File

@ -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

19
restart.sh Normal file
View File

@ -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