简体   繁体   中英

Running a C++ program as a service using init.d

I've written a program in C++ that runs on a Raspberry Pi and listens on the built-in serial port (in a loop) for information from a sensor network I have set up. I want this software to run when the pi boots up, so I've written an init script for this purpose. The script successfully starts the process, as data gets logged to my database, but whenever I use "service sensorlogger start", I get this:

[....] Starting the process: sensorlogger

which just sits on my command line until I ^C to end the program.

  • Why is it that even though the process is running, I'm not getting my terminal back and what might I look into to fix it?
  • Will this prevent my process from starting when the pi boots or prevent it from starting other services?

I have an excerpt of my initscript below. I can include the whole script if needed. Thanks in advance for any help I can get with this!

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

try adding the -b option

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM