What is best way of delaying Node-RED startup?

615 views
Skip to first unread message

Walter Kraembring

unread,
May 2, 2016, 10:30:46 AM5/2/16
to Node-RED
Hello,
When rebooting my Pi (or whatever host) running Node-RED I would like to guarantee that some services running in the same host (like mosquitto and others) are fully operational before Node-RED starts and tries to connect to them. What is the best way of achieving this? Is it to edit the file /lib/systemd/system/nodered.service? I am running Jessie and systemd to handle Node-RED execution and nodered.service looks like below (I think this is current standard for Node-RED).

Kind regards, Walter

# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool.
Wants=network.target

[Service]
Type=simple
# Run as normal pi user - feel free to change...
User=pi
Group=pi
Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=128"
#Environment="NODE_RED_OPTIONS=-v"
#WorkingDirectory=/usr/lib/node_modules/node-red/
#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



Nicholas O'Leary

unread,
May 2, 2016, 10:33:57 AM5/2/16
to Node-RED Mailing List
If you are using systemd to start the other services, it is possible to declare dependencies between them - https://fedoramagazine.org/systemd-unit-dependencies-and-order/

Just don't forget that, if you're using the Jessie preinstall version, any customisations you make to nodered.service will get overwritten when you upgrade to a new version of the node-red package.

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Adam S

unread,
May 2, 2016, 10:39:40 AM5/2/16
to Node-RED
I actually tried this myself a while back to make X wait for node-red to start up using the same type of config you posted and I could never get it to work, so I'm also interested in suggestions.  Basically I have a web browser load on boot that goes to a page from an HTTP node but the Pi would log in and load the page before the node-red service was up which obviously gives you a dead page.  For now I just have an HTML file in the home directory that waits 30 seconds and forwards to the node-red page.

Julian Knight

unread,
May 2, 2016, 11:28:27 AM5/2/16
to Node-RED
It works well. Here is my file for node-red:

# See https://gist.github.com/Belphemur/3f6d3bf211b0e8a18d93

#     http://www.freedesktop.org/wiki/Software/systemd/


[Unit]

Description=Node-Red Live2 Instance for Home Automation

Documentation=http://nodered.org/docs


After=syslog.target network.target mongodb.service mosquitto.service


[Service]

Environment="NODE_OPTIONS=--max-old-space-size=128"

#Environment="NODE_RED_OPTIONS=-v"

#Full Path to Node.js

ExecStart=/usr/local/bin/node $NODE_OPTIONS server.js
$NODE_RED_OPTIONS

#ExecStart=/usr/local/bin/node server.js

WorkingDirectory=/home/pi/node/nr-live2

# User/Group that launches node-RED (it's advised to
create a
new user for Node-RED)

# You can do : sudo useradd node-red

# then change the User=root by User=node-red

User=pi

Group=pi

Nice=10

SyslogIdentifier=NR-Live2

StandardOutput=syslog

# Make Node-RED restart if it fails

Restart=on-failure

#Restart=always

#RestartSec=100

# Node-RED need a SIGINT to be notified to stop

KillSignal=SIGINT


[Install]

WantedBy=multi-user.target


The "after" part is the important bit. This tells systemd not to start node-red until syslog, networking, mongodb and mosquitto have been started.

Walter Kraembring

unread,
May 2, 2016, 2:30:24 PM5/2/16
to Node-RED
Excellent, thank you!
Reply all
Reply to author
Forward
0 new messages