Updated 2022-07-04 !
- a test environment for Node-Red(NR), separated from production
- separated instances for different applications
Setup will follow for a Raspberry Pi(RPi) including how to auto start at power on.
A post for NR quick install.
Directory for the new instance
A post for NR quick install.
Directory for the new instance
Here I assume that I will be running a new project called "p1", and therefore I add a new subdirectory in the Node-Red directory. Log on to the Raspberry with terminal/ssh.
bash nrp1.sh
Autostart
If You want to have the "p1" instance to start at power on and restart at failure add a service file for systemd. Copy the original service file as the base for the "p1" instance with
and edit it with
sudo systemctl stop noderedp1
sudo systemctl disable noderedp1
and then delete the ”noderedp1.service” file.
Inspiration
Got inspiration, among others, from Steve.
mkdir .node-red/p1
The original settings for Nod-Red is ".node-red/settings.js" and I use this as base for the new instance, with command
cp .node-red/settings.js .node-red/p1/settings.js
nano .node-red/p1/settings.js
Settings
You could edit the "p1" settings with
nano .node-red/p1/settings.js
but the overrides will be done in the command.
Start the new instance
Start with
The "p1" instance will be up and running as long as You stay in the ssh session. Terminate with Ctrl + c.
Another tip could be to create a file "nrp1.sh" and add a row with the command "node-red -u /home/pi/.node-red/p1/ -p 1881" and then save. Then it's easy to start the "p1" instance with just
node-red -u /home/pi/.node-red/p1/ -p 1881
Option "-u" points to the "p1" user directory, with it's settings file, and "-p" redirects to port 1881. Command line usage.
The new instance can be accessed at
http://Your-host:1881/
The "p1" instance will be up and running as long as You stay in the ssh session. Terminate with Ctrl + c.
Another tip could be to create a file "nrp1.sh" and add a row with the command "node-red -u /home/pi/.node-red/p1/ -p 1881" and then save. Then it's easy to start the "p1" instance with just
bash nrp1.sh
Autostart
If You want to have the "p1" instance to start at power on and restart at failure add a service file for systemd. Copy the original service file as the base for the "p1" instance with
sudo cp /lib/systemd/system/nodered.service /lib/systemd/system/noderedp1.service
and edit it with
sudo nano /lib/systemd/system/noderedp1.service
Change the ExecStart line to
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS -u /home/pi/.node-red/p1/ -p 1881
and save. Activate the service with
sudo systemctl daemon-reload
sudo systemctl enable noderedp1
Created symlink /etc/systemd/system/multi-user.target.wants/noderedp1.service → /lib/systemd/system/noderedp1.service.
sudo systemctl start noderedp1
sudo systemctl enable noderedp1
Created symlink /etc/systemd/system/multi-user.target.wants/noderedp1.service → /lib/systemd/system/noderedp1.service.
sudo systemctl start noderedp1
Check status with
sudo systemctl status nodered*
If You want to delete the systemd service, for the "p1" project, do
sudo systemctl disable noderedp1
and then delete the ”noderedp1.service” file.
Inspiration
Got inspiration, among others, from Steve.
Thank you for documenting this, it worked well for me. I have been searching for this ability for awhile now and this was the first example I could follow successfully. Appreciate your time.
ReplyDeleteThx !
DeleteMerci pour cette procédure claire et efficace. Suivie ligne à ligne et fonctionne parfaitement.
ReplyDeleteMerci ! 👍
DeleteThanks for your post. Let's say we have another instance named p2 and port is 1882.
ReplyDeletecan we start p1 and p2 in the same time ? and can we open(activate) p1/ui and p2/ui in the same time ?
Thx. Yes, You can have several instances running at the same time, cause they are running with different port numbers. Just adress the UI:s accordingly.
DeleteThank you very much, you saved my day. Now I have one Node for "Back Office" and one for Front. Exactly what i needed!
ReplyDeleteThank you :)
ReplyDelete👍
DeleteThanks a lot for posting this. This is great info. Worked really well for me.
ReplyDeleteThx!
DeleteThanks a lot
ReplyDeleteNice I could help !
Deleteとても助かりました!ありがとうございます!!
ReplyDelete👍
Delete