Modifications

Sauter à la navigation Sauter à la recherche
3 331 octets ajoutés ,  2 avril 2017 à 09:40
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{Rasp-Node-Red-NAV}}
 
{{Rasp-Node-Red-NAV}}
 +
 +
== Raspbian Whezzy et Service ==
 +
Node-Red is great out of the box but it can be a bit manual to start, stop and run on boot. The following section will describe a simple init script to do all of the hard work for us.
 +
 +
Firstly we create a new init.d file, which is essentially a script for starting, stopping and restarting services under Linux.
 +
 +
<syntaxhighlight lang="bash">
 +
sudo nano /etc/init.d/node_red
 +
</syntaxhighlight>
 +
 +
Then copy and paste the following code in to the file. To do this within nano copy the text below and right click in the nano window you should see the text start to appear.
 +
 +
The only thing you may need to change before saving is the directory where node-red is installed on your Pi. If you have been following this guide all the way through you do not need to change anything.
 +
 +
For those that have installed Node-Red in a different location just change the following line “cd /home/pi/node-red” to reflect the folder location where Node-Red is installed.
 +
 +
<syntaxhighlight lang="bash">
 +
#! /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
 +
# Note: this runs as the user called pi
 +
 +
PIDFILE=/var/run/nodered.pid
 +
 +
#Load up node red when called
 +
case "$1" in
 +
 +
start)
 +
        echo "Starting Node-Red.."
 +
        su -l pi -c "cd node-red; screen -dmS red node --max-old-space-size=64 red.js
 +
        echo `screen -ls red | sed -n '2p' | cut -f1 -d.` > $PIDFILE
 +
# or
 +
        #nohup node --max-old-space-size=128 red.js > /var/log/node-red.log &
 +
        #echo $! > $PIDFILE
 +
;;
 +
 +
stop)
 +
        echo "Stopping Node-Red.."
 +
        su -l pi -c "screen -S red -X quit"
 +
# or
 +
        #kill `cat $PIDFILE`
 +
        rm -f $PIDFILE
 +
;;
 +
 +
restart)
 +
        echo "Restarting Node-Red.."
 +
        $0 stop
 +
        $0 start
 +
;;
 +
*)
 +
        echo "Usage: $0 {start|stop|restart}"
 +
        exit 1
 +
esac
 +
</syntaxhighlight>
 +
 +
Once you have pasted and updated the above script hit CTRL+X and then Y to save changes. Next we will make the file executable so that it can be run.
 +
 +
<syntaxhighlight lang="bash">
 +
sudo chmod +x /etc/init.d/node_red
 +
</syntaxhighlight>
 +
 +
Finally to ensure the script will start at boot and stop at shutdown we need to update the rc.d file.
 +
 +
<syntaxhighlight lang="bash">
 +
sudo update-rc.d node_red defaults
 +
</syntaxhighlight>
 +
 +
Thats it! Nice and simple, as stated at the start the following commands will now work.
 +
 +
<syntaxhighlight lang="bash">
 +
sudo service node_red start
 +
sudo service node_red stop
 +
sudo service node_red restart
 +
</syntaxhighlight>
 +
 +
The final part to managing Node-Red is keeping it up to date. Since we cloned the Node-Red repository originaly from Git Hub we can easily pull down the latest versions whenever we want.
 +
 +
To do this it is as simple as navigating to the home directory of your installation:
 +
 +
<syntaxhighlight lang="bash">
 +
cd ~/node-red/
 +
</syntaxhighlight>
 +
 +
And to then run git pull
 +
 +
<syntaxhighlight lang="bash">
 +
sudo git pull
 +
</syntaxhighlight>
 +
 +
If there are any changes you will see them being downloaded. You can then restart Node-Red using our service script and you are ready to go again.
 +
 +
== Raspbian Jessie et SystemD ==
    
Voir le point [http://nodered.org/docs/hardware/raspberrypi "Adding Autostart capability using SystemD" sur cette page]  
 
Voir le point [http://nodered.org/docs/hardware/raspberrypi "Adding Autostart capability using SystemD" sur cette page]  
    
{{Rasp-Node-Red-TRAILER}}
 
{{Rasp-Node-Red-TRAILER}}
29 922

modifications

Menu de navigation