Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 初始化脚本在启动时不工作-否则可以正常工作_Python_Linux_Init_Sysv - Fatal编程技术网

Python 初始化脚本在启动时不工作-否则可以正常工作

Python 初始化脚本在启动时不工作-否则可以正常工作,python,linux,init,sysv,Python,Linux,Init,Sysv,我基于双叉方法编写了一个python守护进程 当直接使用start | stop参数调用scsdaemon.py时,它可以很好地工作,当raspberry已经启动时,下面的init脚本也可以工作 我已通过运行sudo update rc.d scsdaemon defaults确保在引导期间调用脚本,并确保它是可执行的: $ ls -l /etc/init.d/scsdaemon -rwxr-xr-x 1 root root 1639 Mar 14 19:25 /etc/init.d/scsda

我基于双叉方法编写了一个python守护进程

当直接使用start | stop参数调用
scsdaemon.py
时,它可以很好地工作,当raspberry已经启动时,下面的init脚本也可以工作

我已通过运行
sudo update rc.d scsdaemon defaults
确保在引导期间调用脚本,并确保它是可执行的:

$ ls -l /etc/init.d/scsdaemon
-rwxr-xr-x 1 root root 1639 Mar 14 19:25 /etc/init.d/scsdaemon
我已经将重定向到
/tmp
中文件的echo语句放入init脚本中,因此可以验证脚本是否已运行。
但是服务没有启动。日志中没有一条消息,应用程序创建的日志也在那里,但为空

我错过了什么?为什么这在正常运行期间有效,但在引导期间无效

#!/bin/sh

### BEGIN INIT INFO
# Provides:          scsdaemon
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Put a short description of the service here
# Description:       Put a long description of the service here
### END INIT INFO

# Change the next 3 lines to suit where you install your script and what you want to call it
DIR=/var/www/bin/py
DAEMON=$DIR/scsdaemon.py
DAEMON_NAME=scsdaemon

# Add any command line options for your daemon here
DAEMON_OPTS=""

# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=www-data

# The process ID of the script when it runs is stored here:
PIDFILE=/tmp/$DAEMON_NAME.pid

. /lib/lsb/init-functions

do_start () {
    log_daemon_msg "Starting system $DAEMON_NAME daemon"
    start-stop-daemon --start --user $DAEMON_USER --chuid $DAEMON_USER --exec $DAEMON -- start $DAEMON_OPTS
    log_end_msg $?
}
do_stop () {
    log_daemon_msg "Stopping system $DAEMON_NAME daemon"
    start-stop-daemon --start --exec $DAEMON --retry 10 -- stop $DAEMON_OPTS
    log_end_msg $?
}

case "$1" in

    start|stop)
        do_${1}
        ;;

    restart|reload|force-reload)
        do_stop
        do_start
        ;;

    status)
        status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
        ;;

    *)
        echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
        exit 1
        ;;

esac
exit 0

在守护进程中是否有一个异常处理程序,该处理程序包装所有内容并在引发异常时记录错误消息?由于系统即将启动,守护进程可能正在接触一些尚不可用的内容。我正在使用守护进程构造函数的stdout/stderr参数指定一个.out和一个.err文件,以将输出/错误写入双分叉进程。但是那些文件里什么都没有。