8
7

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.

nginxをrestartせずに入れ替えるシェルスクリプト

Posted at

一々DNSから外して入れ替えてまた投入してとか面倒なので。
クライアント側からは止まったようには感じられない、はず。

reinstall_nginx.sh
# nginxのパスが通ってることを期待
OLD_PID=`cat /var/run/nginx.pid`

echo -n "make new master. "
sudo kill -USR2 ${OLD_PID}
MASTER=`ps ax|grep '[ n]ginx: master'|wc -l`
while [ $MASTER -eq 1 ] ; do
    sleep 1
    MASTER=`ps ax|grep '[ n]ginx: master'|wc -l`
    echo -n .
done
echo "ready"

# 高負荷環境だとココで数分待たされるかも
echo -n "shutting down old workers. "
sudo kill -WINCH ${OLD_PID}
WORKER=`ps axo ppid,pid|grep ${OLD_PID}|wc -l`
while [ $WORKER -gt 2 ] ; do
    sleep 1
    WORKER=`ps axo ppid,pid|grep ${OLD_PID}|wc -l`
    echo -n .
done
echo "killed"

sudo kill -QUIT ${OLD_PID}
echo "old master(${OLD_PID}) killed"
8
7
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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?