After this command, using the sudo forever list i can see the process, but i can't access to the dashboard with the browser. Does anybody can help me to find the problem? I installed forever with the command sudo npm install forever -g . I also tried to increase the minuptime and spinsleeptime up to 10000, but it did'n change anything.
Thank you!
Edit: also tried sudo /usr/bin/forever start --minUptime 10000 --spinSleepTime 10000 /usr/bin/node-red-pi without success.
I'd like to run multiple instances of node red, and i'm trying to launch them with forever. Do you know other ways to do that? I know i could try with docker, but i wanted to find simpler ways before.
I haven't tried it but if you make a copy /lib/systemd/system/nodered.service in the same folder called, for example nodered1.service, or some more meaningful name and edit it so that it starts one of your node reds (it is pretty simple, have a look) then you can start it with sudo systemctl start nodered1
replacing start with stop or restart as necessary, and to make it run automatically on boot sudo systemctl enable nodered1
and use disable to stop it starting automatically. Assuming that works then make additional service files one for each nodered instance.
Thank you for the suggestion. I found the nodered.service file. I didn't find anything about the settings.js path and the user folder, which i inserted in my command:
# 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=pi
Group=pi
WorkingDirectory=/home/pi
Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=256"
# 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"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog
[Install]
WantedBy=multi-user.target
Do you know how can i insert the two options --settings .node-red_username/settings.js -u .node-red_username ?
Just stick them on the end of the ExecStart line or add them into the NODE_OPTIONS definition, that is the command that gets run. Also check that User, Group and WorkingDirectory are what you want. You could change SyslogIdentifier if you wanted so you can separate the logs. Also you could change the Description.
# 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=pi
Group=pi
WorkingDirectory=/home/pi/.node-red_username
Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=64"
# 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"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTION --settings .node-red_username/settings.js -u .node-red_username
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog
[Install]
WantedBy=multi-user.target
I changed the working directory and i added the options in the ExecStart line. But it doesn't work, except for the original instance on port 1880. Is it possible that i'm using wrong ports? I need 3 instances, and i'm using ports 1880, 1881, 1882.
If you watch syslog while you start the service by opening a second terminal and running
tail -f /var/log/syslog
then start the service from another terminal window, you should see it starting up.
My best guess is that the path to the settings file is wrong. You have specified /home/pi/.node-red_username as the working dir and then .node-red_username/settings.js as the file. I suggest putting the full path for the settings file. In fact with the working directory specified you might not need the settings file spec at all. I don't know. You should see which file it is trying to use from syslog.
Yes! That was the problem. Writing twice the path made the rpi looking for the directory .node-red_username/.node-red_username . So the file needs only a small edit.
# 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=pi
Group=pi
WorkingDirectory=/home/pi/.node-red_username
Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=64"
# 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"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTION --max-old-space-size=64 --settings settings.js
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog
[Install]
WantedBy=multi-user.target
Try it without the --settings option, I suspect it will work because settings.js is the default. Also if you look a few lines up from there you will see that NODE_OPTIONS is already setting max-old-space so you don't need that either. If I am right then it seems that in fact all that is necessary is to change the working directory.