使用init.d将C ++程序作为服务运行

时间:2014-11-15 20:27:08

标签: c++ linux service init.d

我用C ++编写了一个在Raspberry Pi上运行的程序,并监听内置串口(在循环中),以获取我设置的传感器网络的信息。我希望这个软件在pi启动时运行,所以我为此编写了一个init脚本。当数据记录到我的数据库时,脚本成功启动了该过程,但每当我使用“service sensorlogger start”时,我都会得到:

[....] Starting the process: sensorlogger

只是在我的命令行上,直到I ^ C结束程序。

  • 为什么即使进程正在运行,我也没有让我的终端恢复,我可以调查什么来修复它?
  • 这会阻止我的进程在pi启动时启动或阻止它启动其他服务吗?

我的摘录见下文。如果需要,我可以包括整个脚本。 提前感谢您提供的任何帮助!

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
;;

1 个答案:

答案 0 :(得分:1)

尝试添加-b选项

start-stop-daemon --start --quiet -b --oknodo --pidfile $ PIDFILE --exec $ DAEMON;

相关问题