Différences entre versions de « Rasp-Node-Red-Gerer »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 1 : Ligne 1 :
 
{{Rasp-Node-Red-NAV}}
 
{{Rasp-Node-Red-NAV}}
  
== Raspbian Whezzy et Service ==
+
== Raspbian Whezzy et SystemV ==
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.
+
Node-Red est vraiment au top dès son installation mais il nécessite encore un opération manuelle pour le démarrer (''start''), l'arrêter (''stop'') et démarrer au boot.  
  
Firstly we create a new init.d file, which is essentially a script for starting, stopping and restarting services under Linux.
+
La section suivante décrit comment mettre en oeuvre un "init script" qui effectue le travail pour vous. System V est une collection de script qui supervise le démarrage et l'arrêt des systèmes type Unix. Il était encore utilisé '''jusqu'à Raspbian Whezzy'''. Depuis Raspbian Jessie c'est SystemD qui est utilisé (cfr section suivante).
 +
 
 +
Pour commencer, nous allons créer un nouveau fichier {{fname|init.d}} qui est principalement un script qui démarre, arrête et redémarre les services sous Linux.
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 10 : Ligne 12 :
 
</syntaxhighlight>
 
</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.
+
Ensuite, copiez/collez le code suivant dans le fichier. Pour faire cela avec Nano, copiez le texte suivant dans le presse papier puis faites un clique droit dans la fenêtre de Nano... vous verrez le texte apparaître.
  
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.
+
La seule chose que vous pourriez avoir besoin de changer avant de sauver le fichier c'est le répertoire d'installation Node-Red sur votre ordinateur. Si vous avez attentivement suivit les instructions alors vous ne devriez pas avoir besoin de changer le contenu du fichier.
  
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.  
+
Pour ceux qui on installé Node-Red dans un emplacement différent changer simplement la ligne “cd /home/pi/node-red” pour refléter l'installation actuelle de votre Pi.  
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
Ligne 62 : Ligne 64 :
 
esac
 
esac
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
{{traduction}}
  
 
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.  
 
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.  

Version du 2 avril 2017 à 13:04



MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Raspbian Whezzy et SystemV

Node-Red est vraiment au top dès son installation mais il nécessite encore un opération manuelle pour le démarrer (start), l'arrêter (stop) et démarrer au boot.

La section suivante décrit comment mettre en oeuvre un "init script" qui effectue le travail pour vous. System V est une collection de script qui supervise le démarrage et l'arrêt des systèmes type Unix. Il était encore utilisé jusqu'à Raspbian Whezzy. Depuis Raspbian Jessie c'est SystemD qui est utilisé (cfr section suivante).

Pour commencer, nous allons créer un nouveau fichier init.d qui est principalement un script qui démarre, arrête et redémarre les services sous Linux.

sudo nano /etc/init.d/node_red

Ensuite, copiez/collez le code suivant dans le fichier. Pour faire cela avec Nano, copiez le texte suivant dans le presse papier puis faites un clique droit dans la fenêtre de Nano... vous verrez le texte apparaître.

La seule chose que vous pourriez avoir besoin de changer avant de sauver le fichier c'est le répertoire d'installation Node-Red sur votre ordinateur. Si vous avez attentivement suivit les instructions alors vous ne devriez pas avoir besoin de changer le contenu du fichier.

Pour ceux qui on installé Node-Red dans un emplacement différent changer simplement la ligne “cd /home/pi/node-red” pour refléter l'installation actuelle de votre Pi.

#! /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

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.

sudo chmod +x /etc/init.d/node_red

Finally to ensure the script will start at boot and stop at shutdown we need to update the rc.d file.

sudo update-rc.d node_red defaults

Thats it! Nice and simple, as stated at the start the following commands will now work.

sudo service node_red start
sudo service node_red stop
sudo service node_red restart

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:

cd ~/node-red/

And to then run git pull

sudo git pull

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

Depuis Raspbian Jessie, System 5 (mode de démarrage du système) à été remplacé par SystemD. Vous trouverez ci-dessous des informations traduites depuis le lien "Adding Autostart capability using SystemD" (nodered.org, anglais)

The preferred way to autostart Node-RED on Pi is to use the built in systemd capability. The pre-installed version does this by using a nodered.service file and start and stop scripts. You may install these by running the following commands

sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop
sudo chmod +x /usr/bin/node-red-st*
sudo systemctl daemon-reload

Info: These commands are run as root (sudo) - They download the three required files to their correct locations, make the two scripts executable and then reload the systemd daemon.

Node-RED can then be started and stopped by using the commands node-red-start and node-red-stop (voyez le point précédent pour plus d'informations)

To then enable Node-RED to run automatically at every boot and upon crashes

sudo systemctl enable nodered.service

It can be disabled by

sudo systemctl disable nodered.service

Systemd uses the /var/log/system.log for logging. To filter the log use

sudo journalctl -f -u nodered -o cat

Il est également possible de modifier l'environnement de systemd et utiliser un proxy. Voyez ce lien dans la documentation de nodered.org.



Source: Raspberry Pi Hosting Node-Red
Créé par C. Mobberley pour AdaFruit Industries.

Traduction réalisée et augmentée par Meurisse D. pour MCHobby.be.

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com