Created
March 15, 2016 10:46
-
-
Save xianhuazhou/93ac9f82d95dba490149 to your computer and use it in GitHub Desktop.
gracefully reload php-fpm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SED=/bin/sed | |
NGINX_INIT="/etc/init.d/nginx" | |
NGINX_CONF="/usr/local/nginx/conf/nginx.conf" | |
FPM_1="/etc/init.d/php-fpm" | |
FASTCGI_1="php-fpm.socket" | |
FASTCGI_1_PID="/var/run/php-fpm.pid" | |
FPM_2="/etc/init.d/php-fpm2" | |
FASTCGI_2="php-fpm2.socket" | |
FASTCGI_2_PID="/var/run/php-fpm2.pid" | |
function check_file { | |
if [[ ! -f $1 ]]; then | |
echo "$1 does not exists." | |
exit -1 | |
fi | |
} | |
function start_php_fpm { | |
if [[ -f $1 ]] | |
then | |
echo "$2 stop" | |
$2 stop | |
sleep 1 | |
fi | |
echo "$2 start" | |
$2 start | |
} | |
function use_php_fpm { | |
echo "$1 reload" | |
$1 reload | |
sleep 5 | |
echo "$2 stop" | |
$2 stop | |
} | |
check_file $FPM_1 | |
check_file $FPM_2 | |
if [[ `grep ${FASTCGI_1} $NGINX_CONF` != '' ]] | |
then | |
$SED -i "s/${FASTCGI_1}/${FASTCGI_2}/g" $NGINX_CONF | |
start_php_fpm $FASTCGI_2_PID $FPM_2 | |
sleep 1 | |
use_php_fpm $NGINX_INIT $FPM_1 | |
else | |
$SED -i "s/${FASTCGI_2}/${FASTCGI_1}/g" $NGINX_CONF | |
start_php_fpm $FASTCGI_1_PID $FPM_1 | |
sleep 1 | |
use_php_fpm $NGINX_INIT $FPM_2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment