PHP-FPM在/etc/init.d/php5-fpm stop之后运行

时间:2011-04-28 07:44:06

标签: php

我真的不明白为什么PFM守护进程在我停止后运行。

这是ps aux:

root       998  0.1  0.1 127268  4316 ?        Ss   02:13   0:36 /usr/sbin/php5-fpm --fpm-config /etc/php5/fpm/main.conf
1004       999  0.0  0.1 127812  4628 ?        S    02:13   0:00 /usr/sbin/php5-fpm --fpm-config /etc/php5/fpm/main.conf

这是/etc/init.d/php5-fpm文件

#!/bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm php5-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: starts php-fpm
### END INIT INFO

set -u

DAEMON="PHP5 FPM"
FPM_CMD=/usr/sbin/php5-fpm
FPM_CONF=/etc/php5/fpm/main.conf
FPM_PID=/var/run/php5-fpm.pid
TIMEOUT=30

FPM_OPTIONS="--fpm-config $FPM_CONF"
SSD_OPTIONS="--oknodo --quiet --pidfile $FPM_PID --exec $FPM_CMD"

. /lib/lsb/init-functions

case "$1" in
    start)
        log_begin_msg "Starting $DAEMON..."

        /sbin/start-stop-daemon --start $SSD_OPTIONS -- $FPM_OPTIONS
        log_end_msg $?
    ;;
    stop)
        log_begin_msg "Stopping $DAEMON..."

        /sbin/start-stop-daemon --stop $SSD_OPTIONS
        log_end_msg $?
    ;;
    graceful-stop)
        log_begin_msg "Gracefully stopping $DAEMON..."

        /sbin/start-stop-daemon --stop --retry QUIT/$TIMEOUT/TERM $SSD_OPTIONS
        log_end_msg $?
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    reload|force-reload)
        log_begin_msg "Reloading $DAEMON..."

        /sbin/start-stop-daemon --stop --signal USR2 $SSD_OPTIONS
        log_end_msg $?
    ;;
    *)
        echo "Usage: $0 {start|stop|graceful-stop|restart|reload|force-reload}"
        exit 1
    ;;
esac

我该怎么办?

谢谢!

2 个答案:

答案 0 :(得分:2)

我知道这个帖子现在有点老了,但仍然是一个解决方案

你可以通过设置php-fpm daemonize本身 php-fpm.conf中的daemonize = yes

在配置文件的[global]块中,您可以通过添加以下行来为守护进程添加或设置pid文件: pid = /var/run/php-fpm.pid

然后只是让start-stop-daemon没有为php-fpm进程设置pid,而是使用teh守护进程本身提供的pid

php-fpm的init.d脚本如下所示:

#!/bin/sh
NAME="php-fpm"
DESC="${NAME} deamon script"
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
DAEMON="/usr/local/sbin/php-fpm"
DAEMON_OPTS="--fpm-config=/path/to/php-fpm.conf -c=/path/to/php.ini"
#set this file to the same file as in your php-fpm.conf
PIDFILE="/var/run/${NAME}.pid"
QUIET="--quiet"
START_OPTS="--start ${QUIET} --background --exec ${DAEMON} -- ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"

test -x $DAEMON || exit 0

set -e

case "$1" in
        start)
                echo -n "Starting $DESC: "
                export LD_LIBRARY_PATH="/usr/local/lib/"
                start-stop-daemon $START_OPTS
                echo "$NAME."
        ;;
        stop)
                echo -n "Stopping $DESC: "
                start-stop-daemon $STOP_OPTS
                echo "$NAME."
        ;;
        restart)
                echo -n "Restarting $DESC: "
                start-stop-daemon $STOP_OPTS
                sleep 1
                export LD_LIBRARY_PATH="/usr/local/lib/"
                start-stop-daemon $START_OPTS
                echo "$NAME."
        ;;
        *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop|restart}" >&2
                exit 1
        ;;
esac

exit 0

答案 1 :(得分:0)

我建议你做killall -9 php-fpm并查找php-fpm日志。我想它会挂起处理长PHP脚本,例如set_time_limit(0)ignore_user_abort(true)