[英]Running a C++ program as a service using init.d
我已經用C ++編寫了一個程序,該程序在Raspberry Pi上運行,並在內置串行端口(循環)上偵聽來自已建立的傳感器網絡的信息。 我希望該軟件在pi啟動時能夠運行,因此我為此編寫了一個初始化腳本。 該腳本成功啟動了該過程,因為數據已記錄到數據庫中,但是每當我使用“ service sensorlogger start”時,都會得到以下信息:
[....] Starting the process: sensorlogger
它只是坐在我的命令行上,直到我結束程序。
我的摘錄如下。 如果需要,我可以包括整個腳本。 在此先感謝您提供的任何幫助!
test -x $DAEMON || exit 5
case $1 in
start)
# Checked the PID file exists and check the actual status of process
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
# If the status is SUCCESS then don't need to start again.
if [ $status = "0" ]; then
exit # Exit
fi
fi
# Start the daemon.
log_daemon_msg "Starting the process" "$NAME"
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
嘗試添加-b選項
start-stop-daemon --start --quiet -b --oknodo --pidfile $ PIDFILE --exec $ DAEMON;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.