使 php 脚本作为服务 Linux 运行



我写了一个php脚本,我想在linux中将其作为service/daemon运行。

所以我可以使用服务我的服务start/stop/restart

我假设它需要在/etc/init.d/

您可以在 /etc/init.d 下引用任何预构建的启动脚本,例如 httpd。例如,您可以参考以下内容:

#!/bin/bash
#
# chkconfig: 35 90 12
# description: Foo server
#
# Get function from functions library
. /etc/init.d/functions
# Start the service FOO
start() {
       initlog -c "echo -n Starting FOO server: "
    /path/to/FOO &
    ### Create the lock file ###
    touch /var/lock/subsys/FOO
    success $"FOO server startup"
    echo
}
# Restart the service FOO
stop() {
    initlog -c "echo -n Stopping FOO server: "
    killproc FOO
    ### Now, delete the lock file ###
    rm -f /var/lock/subsys/FOO
    echo
}
### main logic ###
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
 status)
    status FOO
        ;;
 restart|reload|condrestart)
    stop
    start
    ;;
 *)
    echo $"Usage: $0 {start|stop|restart|reload|status}"
    exit 1
esac
exit 0

你可以在这里详细查看

最新更新