ここで、ダブルフォーク方式に基づいて Python デーモンを作成しました。
scsdaemon.py
start|stop 引数を使用して直接 呼び出した場合は完全に機能し、以下の 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
ファイルにリダイレクトされる echo ステートメントを init スクリプトに既に入れている/tmp
ため、スクリプトが実行されていることを確認できます。
しかし、サービスは開始されません。ログに単一のメッセージはなく、アプリケーションが作成するログも空ですが、ログはありません。
私は何が欠けていますか?通常の実行中にこれが機能するのに、起動中に機能しないのはなぜですか?
#!/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