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

来源:互联网 发布:jdk 6u45 windows x64 编辑:程序博客网 时间:2024/06/10 14:59

一个同时启停或者加载配置,用于管理nginx和php-fpm的脚本,可以放在任意目录,也可以放在/etc/init.d/里面,然后chkconfig一下,使其开机启动。

PS:现在用CentOS7的人多么?……


#!/bin/shsource /etc/profileSETCOLOR_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_SUCCESSecho $1$SETCOLOR_NORMALelse$SETCOLOR_FAILUREecho $2$SETCOLOR_NORMALfi}cmd=$1php_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/nullif [ "$?" -eq "0" ]then$php_fpm_bin_path -c $php_fpm_conf_path/php.ini -y $php_fpm_conf_path/php-fpm.conf &> /dev/nullCheckReturn "php-fpm start success!" "php-fpm start failed!"elseecho "php-fpm start test failed!"fi$nginx_bin_path -t &> /dev/nullif [ "$?" -eq "0" ]then$nginx_bin_path &> /dev/nullCheckReturn "nginx start success!" "nginx start failed!"elseecho "nginx start test failed!"fi;;'stop')kill -QUIT `cat /usr/local/php/var/run/php-fpm.pid` &> /dev/nullCheckReturn "php-fpm stop success!" "php-fpm stop failed!"kill -QUIT `cat $nginx_pid_path` &> /dev/nullCheckReturn "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 -tif [ "$?" -eq "0" ]thenkill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`elseecho "php-fpm reload test failed!"fi$nginx_bin_path -tif [ "$?" -eq "0" ]then$nginx_bin_path -s reloadelseecho "nginx reload test failed!"fi;;*)# usageecho "Usage: $0 {start|stop|reload}"exit 1;;esac


0 0