一个管理nginx和php-fpm的脚本

一个同时启停或者加载配置,用于管理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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值