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