1

k8s tomcat 进程 killed 访问 nginx 502 问题

 2 years ago
source link: https://www.v2ex.com/t/808560
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Kubernetes

k8s tomcat 进程 killed 访问 nginx 502 问题

  dunhanson · 3 小时 36 分钟前 · 249 次点击

外部 nginx->ingress->service->pod

dockerfile 启动 catalina.sh 就不会生成 catalina.out 问题

所以第一版的 dockerfile 是这样的

第一版会存在可能 tomcat 进程挂了,但是容器没有挂导致流量会正常过来,导致用户访问返回 nginx 502 错误

sh /usr/local/tomcat/bin/startup.sh
tee /opt/health.sh <<-'EOF'
while true
do
 if test $( ps -aux | grep java | grep tomcat | wc -l ) -eq 0
 then
  ps -aux | grep catalina.out | grep -v grep | awk '{print$2}' | xargs kill -9
 fi
done
EOF
sh /opt/health.sh &
tail -f /usr/local/tomcat/logs/catalina.out

第二版做了改进,增加了一个脚本去进行健康检查(如果 tomcat 进程挂了就结束 tail 进程)

sh /usr/local/tomcat/bin/startup.sh
tee /opt/health.sh <<-'EOF'
while true
do
 if test $( ps -aux | grep java | grep tomcat | wc -l ) -eq 0
 then
  ps -aux | grep catalina.out | grep -v grep | awk '{print$2}' | xargs kill -9
 fi
done
EOF
sh /opt/health.sh &
tail -f /usr/local/tomcat/logs/catalina.out

第二版暂时没发现什么问题,不晓得还有没有其他更简便的方式?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK