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