I'm currently having a node.js script running on my Raspberry PI running Raspbian. That node.js script gets started at boot so I just have to plug in the board.
But, if the script would crash resulting in the exit of node, how could I make the boot service (which starts the node script at bood) auto restart itself when the node service crashed?
Here's an example of my bootservice in /etc/init.d
:
#! /bin/sh
### BEGIN INIT INFO
# Provides: MyScriptService
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts my node.js script.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin
. /lib/init/vars.sh
. /lib/lsb/init-functions
case "$1" in
start)
log_begin_msg "Starting my script"
node /home/pi/myscript.js
log_end_msg $?
exit 0
;;
stop)
log_begin_msg "Stopping my script"
log_end_msg $?
exit 0
;;
*)
exit 1
;;
esac
UPDATE: Been able to fix it myself within Node itself. https://stackoverflow.com/a/50413860/3037607