1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cURLしてHTTPステータスが200以外だったら再起動する

Posted at

背景

弊社の社内システムはLinux+Apache+Tomcatで動いているものがあるのですが、原因不明でTomcatが停止してしまい、HTTP503が発生する現象が発生していました。

言い訳

今どきApacheではなくてnginxにしたいし、Tomcatが停止してしまうのはバグなような気がしますが、それほどクリティカルなシステムでもないし、業務が停止してしまうほどではないので優先度:最低の状態。

表題のとおり

旧時代的な対応ですが、このような対応にしました。まあ、備忘録です。

keepalive.sh
# !/bin/bash

# 死活監視したいURL
REQUEST_URL=http://hoge/paka

HTTP_STATUS=`curl -LI ${REQUEST_URL} -o /dev/null -w '%{http_code}\n' -s`

echo `date '+%y/%m/%d %H:%M:%S'` "HTTP STATUS:"${HTTP_STATUS}

if [ $HTTP_STATUS = "200" ]; then
  echo `date '+%y/%m/%d %H:%M:%S'` "動いているよ!"
  exit;
else
  echo `date '+%y/%m/%d %H:%M:%S'` "死んでいるよ!"
  systemctl restart tomcat.service
fi

cronでこのシェルを実行する場合は環境変数に注意です。
本当はログの出力をしていたけど、それは省略。適当にやってください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?