zoukankan      html  css  js  c++  java
  • 分享一个php的启动关闭脚本(原)

    自己简单写的一个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

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

  • 相关阅读:
    vnpy源码阅读学习(8):关于app
    vnpy源码阅读学习(6):事件引擎
    vnpy源码阅读学习(5):关于MainEngine的代码阅读
    tensorflow 2.1 采坑记
    vnpy源码阅读学习(4):自己写一个类似vnpy的UI框架
    ABP (.Net Core 3.1版本) 使用MySQL数据库迁移启动模板项目(1)
    'vue-cli-service' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    C# Winform版批量压缩图片程序
    小程序开发技巧总结
    ASP.NET WebAPI 双向token实现对接小程序登录逻辑
  • 原文地址:https://www.cnblogs.com/dragonflyer/p/6219227.html
Copyright © 2011-2022 走看看