之前在mac安装了php和nginx每次都用一堆命令重启
今天没事情干,心血来潮,自己研究写了一段shell脚本来重启
首先sudo vim /usr/sbin/pn
代码如下
#! /bin/bash phpdir=/usr/local/php/sbin #安装路径
phpname=php-fpm
phpdaemon=$phpdir/$phpname
phpconfig=/usr/local/php/etc/php.ini nginxdir=/Applications/Xcode.app/Contents/Developer/usr/share/xcs/Nginx/sbin
nginxname=nginx
nginxdaemon=$nginxdir/$nginxname
nginxconfig=/Applications/Xcode.app/Contents/Developer/usr/share/xcs/Nginx/ nginxstart()
{
if test -x $nginxdaemon
then
#echo -e "正在启动Nginx进程: $nginxname"
if $nginxdaemon -p $nginxconfig
then
echo -e "Nginx服务启动成功"
else
echo -e "Nginx服务启动失败"
fi
else
echo -e "找不到Nginx启动服务 ($nginxname)"
fi
}
nginxstop()
{
process_num=`ps -ef | grep nginx | grep -v grep |wc -l`
#echo -e "正在停止Nginx进程: $nginxname"
if [ $process_num -eq ]; then
echo -e "Nginx服务停止成功"
else
if kill `ps -ef | grep nginx | grep -v grep | awk '{print $2}'`
then
echo -e "Nginx服务停止成功"
else
echo -e "Nginx服务停止失败"
fi
fi }
phpstart()
{
if test -x $phpdaemon
then
#echo -e "正在启动PHP进程: $phpname"
if $phpdaemon -c $phpconfig
then
echo -e "PHP服务启动成功"
else
echo -e "PHP服务启动失败"
fi
else
echo -e "找不到PHP启动服务 ($phpname)"
fi
}
phpstop()
{
process_num=`ps -ef | grep php-fpm | grep -v grep |wc -l`
#echo -e "正在停止PHP进程: $phpname"
if [ $process_num -eq ]; then
echo -e "PHP服务停止成功"
else
if kill `ps -ef | grep php-fpm | grep -v grep | awk '{print $2}'`
then
echo -e "PHP服务停止成功"
else
echo -e "PHP服务停止失败"
fi
fi
} case $ in
start)
phpstart
nginxstart
;;
stop)
phpstop
nginxstop
;;
restart)
phpstop
nginxstop
phpstart
nginxstart
;; *)
echo "---------请输入正确的参数---------"
echo "stop:表示停止PHP和Nginx服务"
echo "start:表示启动PHP和Nginx服务"
echo "restart:表示重启PHP和Nginx服务"
echo "--------------------------------"
exit
;;
esac
exit
然后保存
加执行权限sudo chmod +x /usr/sbin/pn
以上代码不是最简洁的,有兴趣的同学可以自己DIY,原理差不多
以后只要执行 sudo pn restart就可以重启PHP和Nginx啦