• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

分享一个php的启动关闭脚本(原)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

自己简单写的一个php服务的启动脚本和大家分享

思路(实现的原理):

1:function模块+case语句多分支判断

2:通过添加# chkconfig: 2345 43 89注释实现开机自启动(前提是把脚本放入/etc/init.d/目录下 然后chmod给可执行权限,然后chkconfig --add phpd(脚本名称))

3:每次命令执行是否成功用$?是否为0来给予反馈

#!/bin/bash
# php-fpm       Start/Stop php-fpm
#
# chkconfig: 2345 43 89
#author andy
#date 20161218
#function php-fpm manager
#email fei1989118@126.com
#version 1.0
#check service status
#usage
. /etc/init.d/functions
#define var
check=`netstat -lnutp|grep php-fpm|wc -l`
function usage(){

 echo "usage:$0 {start|stop|restart|status}"
 exit
}
function start(){
 
if [ "$1" = "start" -a $check -ne 0 ];then
 action "php is already started!" /bin/false
 exit
elif [ "$1" = "start" -a $check -eq 0 ];then
 sleep 1
 /usr/local/sbin/php-fpm
  if [ $? = 0 ];then
  action "php start successfully!" /bin/true
  else 
  action "php start failed!" /bin/false
  exit
  fi
fi
}
function stop(){
if [ "$1" = "stop" -a $check -eq 0 ];then
action "php is not running!" /bin/false
 exit
elif [ "$1" = "stop" -a $check -ne 0 ];then
   killall php-fpm
  sleep 1
  if [ $? = 0 ];then
   action "php stoped successfully!" /bin/true
  else
   action "php stoped failed!" /bin/false
  exit
  fi
fi
}
function restart(){
if [ "$1" = "restart" -a $check -eq 0 ];then
  action "php is not running!" /bin/false
  sleep 1
  /usr/local/sbin/php-fpm
  if [ $? = 0 ];then
  action "php start successfully!" /bin/true
  else
  action "php start failed!" /bin/false
  exit
  fi 

elif [ "$1" = "restart" -a $check -ne 0 ];then
   killall php-fpm
  if [ $? = 0 ];then
   action "php stoped successfully!" /bin/true
  else
   action "php stoped failed!" /bin/false
  fi
  sleep 1
  /usr/local/sbin/php-fpm
  if [ $? = 0 ];then
   action "php start successfully!" /bin/true
  else
   action "php start failed!" /bin/false
  exit
  fi
fi

}
function status(){
if [ "$1" = "status" -a $check -eq 0 ];then
  echo "php is not running!"
 exit
elif [ "$1" = "status" -a $check -ne 0 ];then
  echo "php is running"
  exit
fi
}

case "$1" in
    start) start $1
    ;;
    stop) stop $1
    ;;
    restart) restart $1
    ;;
    status) status $1
    ;;
    *) usage $1
esac

如果有不对的地方请多多指正


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
php生成唯一订单号的方法发布时间:2022-07-10
下一篇:
php验证邮箱是否合法发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap