Node-red multiple instances

Hi! I followed this guide to get another instance running: duplicate settings file, different port, mapped to different subdomain (nginx). How should I have this start automatically like my primary instance (which was was installed via the pi script, running as a service). Thanks!

Have you thought about asking 'Steve', the author of that website? Looks like he is very active and commented on a question just a few days ago.

Good idea - thanks!

The tutorial references where the node red service start is specified. I am wondering if I can simply duplicate the statement to start the two instances.

If you want to load node-red on startup with a different settings file than the settings.js you will need to edit the file /lib/systemd/system/nodered.service.

un-comment the line ExecStart if not already done and the Environment=”NODE_RED_OTPIONS=-v” line to something like:

Environment="NODE_RED_OPTIONS=-s /home/pi/.node-red/mysettings.js"
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu

Environment="NODE_OPTIONS=--max_old_space_size=512"
# define an optional environment file in Node-RED's user directory to set custom variables externally
EnvironmentFile=-/home/ubuntu/.node-red/EnvironmentFile
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
# uncomment next line if you need to wait for time sync before starting
#ExecStartPre=/bin/bash -c '/bin/journalctl -b -u systemd-timesyncd | /bin/grep -q "systemd-timesyncd.* Synchronized to time server"'

ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
RestartSec=20
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

You need a service file for each instance. Then you can individually control them, and they will individually restart in the case of crashes.

Do I simply duplicate the "nodered.service" file and enable the same way as during the primary install?

sudo systemctl enable nodered.service

Yes, apart from making whatever changes are necessary to start the right instance, obviously.

Works - thanks!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.