Skip to content

Instantly share code, notes, and snippets.

@Oliv4945
Forked from bigmonkeyboy/README.md
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oliv4945/ebf2a6275eb35a339bf2 to your computer and use it in GitHub Desktop.
Save Oliv4945/ebf2a6275eb35a339bf2 to your computer and use it in GitHub Desktop.

This gist creates an init.d script to automatically run Node-RED at boot time.

To run it as a single step you can cut paste the following single line command

From https://gist.github.com/bigmonkeyboy/ , thanks !

sudo wget -O /tmp/download https://gist.github.com/Oliv4945/ebf2a6275eb35a339bf2/download && sudo tar -zxf /tmp/download --strip-components 1 -C /etc/init.d && sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults

or click right-click "save as" this link - But please read the script first and satisfy yourself it's safe to execute in your environment...

#! /bin/sh
# Starts and stops Node-RED
# /etc/init.d/nodered
### BEGIN INIT INFO
# Provides: node-red
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Node-RED initialisation
### END INIT INFO
# Can be downloaded and installed in one go by using this command
# sudo wget -O /tmp/download https://gist.github.com/bigmonkeyboy/9962293/download && sudo tar -zxf /tmp/download --strip-components 1 -C /etc/init.d && sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults
# This runs as the user called pi - please change as you require
USER=root
# The log is written to here - please make sure your user has write permissions.
LOG=/var/log/node-red.log
#Load up node red when called
case "$1" in
start)
if pgrep ^node-red$ > /dev/null
then
echo "Node-RED already running."
else
echo "Starting Node-Red.."
touch $LOG
chown $USER:$USER $LOG
echo "" >> $LOG
echo "Node-RED service start: "$(date) >> $LOG
# su -l $USER -c "cd ~/.node-red && screen -dmS red node-red-pi --max-old-space-size=128"
# or
su -l $USER -c "node-red-pi --max-old-space-size=128 -u ~/.node-red /home/pi/NoteRF-Soft/NodeRed_Flow/NoteRF_flow.json >> $LOG &"
echo "Logging to "$LOG
fi
;;
stop)
echo "Stopping Node-Red.."
# su -l $USER -c "screen -S red -X quit"
# or
pkill -SIGINT ^node-red$
sleep 2
echo "" >> $LOG
echo "Node-RED service stop: "$(date) >> $LOG
;;
restart)
echo "Restarting Node-Red.."
$0 stop
sleep 2
$0 start
echo "Restarted."
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment