Shell篇之编写php启动脚本
1. 脚本内容
vim php-fpm_ctl.sh
#!/bin/bash
function_start(){
/opt/nginx/php/php-fpm start
}
function_stop(){
/opt/nginx/php/php-fpm stop
}
function_restart(){
/opt/nginx/php/php-fpm restart
}
function_status(){
cgi_stat=0
cgi_tmpa=`ps -ef | grep cgi | grep root | grep -v grep | awk '{print $2}'`
cgi_tmpb=`cat /opt/nginx/php/logs/php-fpm.pid`
if [ `lsof -i:9000 | wc -l` -gt 0 ]; then
if [ `ps -ef | grep php-cgi | grep -v grep | wc -l` -gt 0 ]; then
if [ $cgi_tmpa -eq $cgi_tmpb ]; then
cgi_stat=1
fi
fi
fi
if [ $cgi_stat -eq 1 ]; then
echo "fastcgi(pid $cgi_tmpa) is runing!"
elif [ $cgi_stat -eq 0 ]; then
echo "cgi is not runing!"
fi
}
if [ "$1" = "start" ]; then
function_start
elif [ "$1" = "stop" ]; then
function_stop
elif [ "$1" = "restart" ]; then
function_restart
elif [ "$1" = "status" ]; then
function_status
else
printf "Usage: automate {start|stop|restart|status} \n"
fi
2. 赋权
chmod +x php-fpm_ctl.sh
3. 命令
./php-fpm_ctl.sh start
./php-fpm_ctl.sh status
./php-fpm_ctl.sh restart