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