获取容器状态
portal_id=$(/usr/local/bin/docker ps -q -f name=portal)
if [ -z "$portal_id" ]; then
echo "portal container is died " >> /tmp/check_portal.log
if [ -f /dragonball/portal1/log/portal_flag ];then
echo "because it is being restarted by user" >> /tmp/check_portal.log
else
echo "portal container need to be pull up by scripts" >> /tmp/check_portal.log
if ps -ef|grep restart_portal.sh |grep -v 'grep' > /dev/null 2>&1;then
echo "restart_portal.sh is running" >> /tmp/check_portal.log
else
echo "restart_portal ${portal_ip}" >> /tmp/check_portal.log
restart_portal ${portal_ip}
echo "restart_portal ${portal_ip} finished" >> /tmp/check_portal.log
fi
fi
else
echo "protal container [$portal_id] is alive, nothing to do." >> /tmp/check_portal.log
fi
内存清理
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> /var/log/mem.log
date >> /var/log/mem.log
echo "Memory usage | [Use:${used}MB][Free:${free}MB]" >> /var/log/mem.log
if [ $free -le 1024 ] ; then
sync && echo 1 > /proc/sys/vm/drop_caches
sync && echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches
echo "OK" >> /var/log/mem.log
else
echo "Not required" >> /var/log/mem.log
fi
sed替换
sed -i "s/\<localip\>/$this_ip/" $home_path/dragonball/base/tools/watcher.sh
获取进程pid
ntpd_pid=$(ps -ef | grep "ntpd" | grep -v grep | awk '{print $2}') > /dev/null
重启服务
if [ "$ntpd_pid" == "" ];then
service ntpd restart > /dev/null 2>&1
fi
获取tokens
ip=$1
curl -X GET "http://${ip}:8500/v1/kv/dragonball/tokens/${ip}" >/tmp/token_temp 2>/dev/null
token_=$(awk -F, '{print $4}' /tmp/token_temp | cut -d\" -f4)
token=$(echo $token_ | base64 -d)
echo "'http://${ip}:8888/v1/container/start' -d 'containerName=portal1&token=$token'" >> /tmp/check_portal.log
curl -X POST "http://${ip}:8888/v1/container/start" -d "containerName=portal1&token=${token}" -v
实现大段文本输入
cat >&/etc/ntp.conf <<EOF
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict ::1
server 127.127.1.0
fudge 127.127.1.0 stratum 8
server portal_ip prefer
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOF
端口测试
result=`echo -e "\n" | telnet $IPADDR $PORT 2>/dev/null | grep Connected | wc -l`
if [ $result -eq 1 ]; then
echo "Network is Open."
else
echo "Network is Closed."
fi
网友评论