一个同时启停或者加载配置,用于管理nginx和php-fpm的脚本,可以放在任意目录,也可以放在/etc/init.d/里面,然后chkconfig一下,使其开机启动。
PS:现在用CentOS7的人多么?……
#!/bin/sh
source /etc/profile
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
function CheckReturn
{
if [ "$?" -eq "0" ]
then
$SETCOLOR_SUCCESS
echo $1
$SETCOLOR_NORMAL
else
$SETCOLOR_FAILURE
echo $2
$SETCOLOR_NORMAL
fi
}
cmd=$1
php_fpm_bin_path="/usr/local/php/sbin/php-fpm"
php_fpm_conf_path="/usr/local/php/lib"
nginx_bin_path="/usr/local/nginx/sbin/nginx"
nginx_pid_path="/usr/local/nginx/nginx.pid"
case "$cmd" in
'start')
ulimit -SHn 65535
$php_fpm_bin_path -c $php_fpm_conf_path/php.ini -y $php_fpm_conf_path/php-fpm.conf -t &> /dev/null
if [ "$?" -eq "0" ]
then
$php_fpm_bin_path -c $php_fpm_conf_path/php.ini -y $php_fpm_conf_path/php-fpm.conf &> /dev/null
CheckReturn "php-fpm start success!" "php-fpm start failed!"
else
echo "php-fpm start test failed!"
fi
$nginx_bin_path -t &> /dev/null
if [ "$?" -eq "0" ]
then
$nginx_bin_path &> /dev/null
CheckReturn "nginx start success!" "nginx start failed!"
else
echo "nginx start test failed!"
fi
;;
'stop')
kill -QUIT `cat /usr/local/php/var/run/php-fpm.pid` &> /dev/null
CheckReturn "php-fpm stop success!" "php-fpm stop failed!"
kill -QUIT `cat $nginx_pid_path` &> /dev/null
CheckReturn "nginx stop success!" "nginx stop failed!"
;;
'reload')
$php_fpm_bin_path -c $php_fpm_conf_path/php.ini -y $php_fpm_conf_path/php-fpm.conf -t
if [ "$?" -eq "0" ]
then
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
else
echo "php-fpm reload test failed!"
fi
$nginx_bin_path -t
if [ "$?" -eq "0" ]
then
$nginx_bin_path -s reload
else
echo "nginx reload test failed!"
fi
;;
*)
# usage
echo "Usage: $0 {start|stop|reload}"
exit 1
;;
esac