编程语言
首页 > 编程语言> > 对PHP服务器使用start-stop-daemon

对PHP服务器使用start-stop-daemon

作者:互联网

我正在使用PHP编写的套接字服务器.
这部分工作已经完成,但现在我需要将它作为守护进程运行.

为此,我尝试使用start-stop-daemon,但它不起作用.我的服务器正在运行Debian.

为了简化,我的问题是为什么以下命令不运行我的守护进程或如何调试它?

start-stop-daemon --start --quiet --background --make-pidfile --pidfile /var/run/server-ticket.pid --exec /usr/local/zend/bin/php /var/www/server/consultpilot/ServerTicket.php >> /var/log/server-ticket.log 2>> /var/log/server-ticket.log </dev/null

以下是基于Till Klampaeckel’s tutorial的完整脚本:

#! /bin/sh

### BEGIN INIT INFO
# Provides: ServerTicket
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts ServerTicket
# Description: starts ServerTicket using start-stop-daemon
### END INIT INFO

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/zend/bin/php
DAEMON_OPTS="/var/www/server/consultpilot/ServerTicket.php"
NAME=server-ticket
DESC="Daemon for the Server Ticket from DiffMed"
PIDFILE="/var/run/${NAME}.pid"
LOGFILE="/var/log/${NAME}.log"
QUIET="--quiet"
START_OPTS="--start ${QUIET} --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"    

test -x $DAEMON || exit 0

set -e

case "$1" in
    start)
        echo -n "Starting $DESC: "
        start-stop-daemon $START_OPTS >> "${LOGFILE}" 2>> "${LOGFILE}" </dev/null
        echo "$NAME."       
        ;;
    stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon $STOP_OPTS
        echo "$NAME."
        rm -f $PIDFILE
        ;;
    restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon $STOP_OPTS
        sleep 1
        start-stop-daemon $START_OPTS
        echo "$NAME."
        ;;
*)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0

有关信息,当我开始这个过程时,没有回报.
但是当我完成它时,它告诉我没有进程对应:

root:/var/run$service server-ticket start
Starting Daemon for the Server Ticket from DiffMed: result : 0
server-ticket.
root:/var/run$service server-ticket stop
Stopping Daemon for the Server Ticket from DiffMed: start-stop-daemon: warning: failed to kill 5772: No such process
1 pids were not killed
No process in pidfile '/var/run/server-ticket.pid' found running; none killed.

解决方法:

从start-stop-daemon(8)手册页:

-x, – exec executable检查作为此可执行文件实例的进程(根据/ proc / pid / exe)

这意味着它将检查/usr/local/zend / bin / php的实例,如果它发现它们没有启动新进程.如果你有魔法饼干:

#! /usr/local/zend/bin/php

在/var/www/server/consultpilot/ServerTicket.php脚本的第一行,并确保它可以使用chmod执行,然后您可以将其更改为:

DAEMON=/var/www/server/consultpilot/ServerTicket.php

并获得您期望的结果.

标签:init-d,php,daemon
来源: https://codeday.me/bug/20190810/1638319.html