Ubuntu 22 Node-red systemctl startup issue

Hi all,

Hope someone could maybe help me out with this issue id been experiencing recently.
Not to make life hard for myself. I have a fresh install ubuntu server 22 64bit. i am the root
user and installed it the following way. I was root btw and I know this isnt advised...
But I want to run it as root
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc
nvm install v20.9.0 (latest supported lts by node red currently)
npm install -g --unsafe-perm node-red node-red-admin
systemctl enable nodered.service

It responds with the following
Failed to enable unit: Unit file nodered.service does not exist.
i looked into this file for the systemctl file
https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered
https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service
also looked at this

Neither seem to work and had modified the user, group and working directory to /root
Here is my current node-red.service file

# systemd service file to start Node-RED

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

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

Environment="NODE_OPTIONS=--max_old_space_size=2048"
# define an optional environment file in Node-RED's user directory to set custom variables externally
EnvironmentFile=-/root/.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.* Synchroni>

#ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/root/.nvm/versions/node/v20.9.0/bin/node-red $NODE_OPTIONS $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

I really really dont want to use a pi user or have a config file that doesnt make sense for this server.
Please any help would be really appreciated

Really, don't run as root. So far I have never come across a real need to do that. I recommend creating a node red user then logon as that user and use the recommended Ubuntu install script. Then you should be able to give that user whatever permissions it needs to do whatever you require, but no more.

First, however get rid of nvm, it just causes problems. Also I suggest uninstalling node red and nodejs first. Also remove the service file you have created. The install script will create it for you.

1 Like

nvm almost certainly does not give you the right environment when running node-red from systemd with user/group of root. And I'm afraid, you likely won't get much sympathy or help here in the forum for doing that it is just too troublesome to troubleshoot.

Install, as Colin says, using a proper user/group that you've created to run Node-RED and do so without nvm since every time you change the nvm environment, it will mess up everything you have installed - particularly everything installed globally with npm. You have to re-install for every nvm environment you set up.

You are also trying to use node.js v20 which we know causes some issues with some contributed nodes at least. Stick to v18 for now.

I've a fully commented systemd startup script example that you can customise in the alternate installer repo:

@Colin
This may be ...lame as for rationals sake.As much as a script really makes things alot easier.
Im looking for a manual install method. Scripts can do things you either arent sure of or dont
suite your use case. whether it be expected install paths. version differences or file names.
How can i revert back? purging my current node-red, node, npm and nvm in a clean way?

@TotallyInformation
I hear you, I really dont want to run into any permission related issues down the line. We have
another server running node-red as root but the systemd file is in /lib/systemd/system for
the node-red.service. that server is running our historian+grafana and processing of all the data.
It just ....has to go well? the current system locks up unexpectedly so we want to move the processing
and fetching of the data off this system.

Thanks for the heads up on node v18 / v20 issue. had no idea . been using v20 on my pi but then
again that only has a few contributed nodes in use.

thankyou for the commented systemd, Im going to look at that and try to reverse my past efforts to
start from scratch.

How did you install node-red? If you used
npm install -g --unsafe-perm node-red
then you do not need to reinstall it.

For removing nvm and nodejs versions that it has installed I don't know. Try googling for 'completely remove nvm'.

The easiest way to install a good version of nodejs really is to use the script, but you can do it manually of course. You should install from deb.nodesource.com.

Then perhaps the only other thing you need to do is to create your node red user and adjust your systemd script accordingly.

Hey Colin thanks man,

well I used that same command. Actually npm install -g --unsafe-perm node-red node-red-admin.
according to a few guides there "should" have been a /etc/systemd/system node-red.service config
file in there and i should have been able to just enable it. but when using the systemctl command to
enable that service it said there was no file there. Also confirmed by physically looking at the location.

nvm i used to get node v20.9.0 and based off yours and TotallyInformation replies i believed id need to
reinstall everything as nvm was at the the base of all of this process. After removing everything first
ofcourse.

Feel like I botched this whole thing

No, that comes with the script, and it is called nodered.service (no dash) and is in /lib/systemd/system/ which is where, I believe, user installed services go, by convention.

To remove node-red you can just use
sudo npm -g remove node-red

1 Like

That is the root folder. Many of the actual scripts will be linked into that location or one of its sub-folders. For example, the alternate installer has an example that uses /etc/systemd/system/multi-user.target.wants/ but I recommend keeping the script somewhere more discoverable and accessible if you might be wanting to amend it at all. Though actually, I also recommend using an env file - you can read the details in the example service script.

Like most things in Linux - it is COMPLEX! :grinning:

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