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