-
-
Save bigmonkeyboy/9962293 to your computer and use it in GitHub Desktop.
| #! /bin/sh | |
| # Starts and stops Node-RED | |
| # /etc/init.d/node-red | |
| ### 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/node-red && sudo update-rc.d node-red defaults | |
| # This runs as the user called pi - please change as you require | |
| USER=pi | |
| # The log is written to here - please make sure your user has write permissions. | |
| LOG=/tmp/node-red.log | |
| #Load up node red when called | |
| case "$1" in | |
| start) | |
| echo "Starting Node-Red.." | |
| # 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 -u ~/.node-red > $LOG &" | |
| echo "Logging to "$LOG | |
| ;; | |
| stop) | |
| echo "Stopping Node-Red.." | |
| # su -l $USER -c "screen -S red -X quit" | |
| # or | |
| pkill -SIGINT node-red | |
| sleep 1 | |
| ;; | |
| restart) | |
| echo "Restarting Node-Red.." | |
| $0 stop | |
| $0 start | |
| ;; | |
| *) | |
| echo "Usage: $0 {start|stop|restart}" | |
| exit 1 | |
| esac |
Hi, I'm trying to run this on a machine with nvm installed. I've set nvm to use 0.12.8 and running node-red from the command line works fine and picks up that version. But using this service, node-red picks up v5.0.0 of node instead. Any idea how I might set version for this script as well?
Hi,
In my case I moved from grep to pidof as I was having strange behavior.
Thanks
@sinewave440hz You'd need to run the nvm script that runs when you use the command line. When you start a shell a file will be run (possibly ~/.bashrc or ~/.profile), and at the end of it nvm appends a line which says something like:
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
fiYou need to add those lines to this script, probably after echo "Starting Node-Red.."
install via curl not working, manual copy to init.d/ works
how did you add node-red as a service i tried runing it from command line it works fine but when i try it running using service node-red start it doesnt start can you help me out
looks like line 23 has been truncated?
su -l pi -c "cd node-red; screen -dmS red node --max-old-space-size=128$
should it be
su -l pi -c "cd node-red; screen -dmS red node --max-old-space-size=128 red.js"