php-fpm和nginx的reload、restart的区别

2018-04-20 21:39:57       xhs

php-fpm和nginx的 reload、restart的区别

  1. reload

    不会停止服务,用于重新加载配置;并且会检查配置文件的语法

  2.  restart 

    会停止服务,重新启动,脚本里写的是执行 stop() 和 start()

  3. php-fpm的脚本

    #! /bin/sh
    #
    # chkconfig: - 84 16
    # description:  PHP FastCGI Process Manager
    # processname: php-fpm
    # config: /opt/remi/php54/root/etc/php-fpm.conf
    # config: /opt/remi/php54/root/etc/sysconfig/php-fpm
    # pidfile: /opt/remi/php54/root/var/run/php-fpm/php-fpm.pid
    #
    ### BEGIN INIT INFO
    # Provides: php-fpm
    # Required-Start: $local_fs $remote_fs $network $named
    # Required-Stop: $local_fs $remote_fs $network
    # Short-Description: start and stop PHP FPM
    # Description: PHP FastCGI Process Manager
    ### END INIT INFO
    
    # Standard LSB functions
    #. /lib/lsb/init-functions
    
    # Source function library.
    . /etc/init.d/functions
    
    # Check that networking is up.
    . /etc/sysconfig/network
    
    # Additional environment file
    if [ -f /opt/remi/php54/root/etc/sysconfig/php-fpm ]; then
          . /opt/remi/php54/root/etc/sysconfig/php-fpm
    fi
    
    if [ "$NETWORKING" = "no" ]
    then
        exit 0
    fi
    
    RETVAL=0
    prog="php-fpm"
    pidfile=${PIDFILE-/opt/remi/php54/root/var/run/php-fpm/php-fpm.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/php54-php-fpm}
    
    start () {
        echo -n $"Starting $prog: "
        dir=$(dirname ${pidfile})
        [ -d $dir ] || mkdir $dir
        daemon --pidfile ${pidfile} /opt/remi/php54/root/usr/sbin/php-fpm --daemonize
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch ${lockfile}
    }
    stop () {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} php-fpm
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ] ; then
            rm -f ${lockfile} ${pidfile}
        fi
    }
    
    restart () {
            stop
            start
    }
    
    reload () {
        echo -n $"Reloading $prog: "
        if ! /opt/remi/php54/root/usr/sbin/php-fpm --test ; then
                RETVAL=6
                echo $"not reloading due to configuration syntax error"
                failure $"not reloading $prog due to configuration syntax error"
        else
            killproc -p ${pidfile} php-fpm -USR2
            RETVAL=$?
        fi
        echo
    }
    
    
    # See how we were called.
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
      status)
        status -p ${pidfile} php-fpm
        RETVAL=$?
        ;;
      restart)
        restart
        ;;
      reload|force-reload)
        reload
        ;;
      configtest)
        /opt/remi/php54/root/usr/sbin/php-fpm --test
        RETVAL=$?
        ;;
      condrestart|try-restart)
        [ -f ${lockfile} ] && restart || :
        ;;
      *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart|configtest}"
        RETVAL=2
            ;;
    esac
    
    exit $RETVAL
    
            

    reload 是这个

        killproc -p ${pidfile} php-fpm -USR2
    stop 是这个
        killproc -p ${pidfile} php-fpm 
    -USR2是操作系统定义的信号,给开发者用于任意用途。其他信号还有 USER1,HUP (重载配置) 参考 Why do many Unix programs use signals like USR1?
  4. nginx的脚本
    参见 Nginx和PHP-FPM的启动/重启脚本


发表评论