a6d5b6
#!/bin/sh
a6d5b6
[ ! -f /run/nginx.pid ] && exit 1
a6d5b6
echo "Start new nginx master..."
a6d5b6
/bin/systemctl kill --signal=SIGUSR2 nginx.service
a6d5b6
sleep 5
a6d5b6
[ ! -f /run/nginx.pid.oldbin ] && sleep 10
a6d5b6
if [ ! -f /run/nginx.pid.oldbin ]; then
a6d5b6
    echo "Failed to start new nginx master."
a6d5b6
    exit 1
a6d5b6
fi
a6d5b6
echo "Stop old nginx master gracefully..."
a6d5b6
oldpid=`/usr/bin/cat /run/nginx.pid.oldbin 2>/dev/null`
a6d5b6
/bin/kill -s QUIT $oldpid 2>/dev/null
a6d5b6
sleep 5
a6d5b6
[ -f /run/nginx.pid.oldbin ] && sleep 10
a6d5b6
if [ -f /run/nginx.pid.oldbin ]; then
a6d5b6
    echo "Failed to stop old nginx master."
a6d5b6
    exit 1
a6d5b6
fi