Installation failure on Rasp Pi running up to date Raspian Buster 10

Trust me - it once was just a few lines like you have... and then as Colin points out we had to cope with few "simple" extra situations... and then problems/issues/suggestions from users... and before you know it... you have a whole heap of code :slight_smile:

1 Like

yep. fully understand.
I just did the "make it boot as a service at start-up" and it's growing arms and legs now.
@dceejay, @Colin
ur quite right, this is not so simple.

#####################################################################
############    get node-red to boot at start-up   ##################
############          on an Armv71 Rasp Pi         ##################
#     reference
#         https://nodered.org/docs/faq/starting-node-red-on-boot


# install pm2
sudo npm install -g pm2

# location of node red. Use this location in the below background command
#### which node-red


# get node red install location which includes start-up file name
install_location="$(which node-red)"
#### echo "$install_location"
####            /usr/local/bin/node-red

install_dir_z="${install_location%/*}"
#### echo "$install_dir_z"
####            /usr/local/bin/

# this will tell node red to run in the background
pm2 start "$install_location" --node-args="--max-old-space-size=128" -- -v

# view information about the process and access the log output using the commands:
#### pm2 info node-red
#### pm2 logs node-red

# startup pm2 on systemd
pm2 startup systemd

# set the paths
sudo env PATH=$PATH:"$(install_diz_z)" /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi

Don't use PM2 on a pi, use systemd. All the scripts are available and will be automatically installed if you run the install/upgrade script.
If you must do it by hand then the service script is https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service and goes into /lib/systemd/system. The other useful scripts are in the same url and are node-red-start node-red-stop node-red-restart node-red-reload and node-red-log.
Surely easier just to run the script though.

1 Like

@Colin I could'nt get the script to run.
See earliear comments

@Colin "use systemd not pm2 to boot node-red at start up"

kind of obvious now.

after script install issues, I had to look up how to install node-red with npm which I know little or nothing about, and which therefore feels slightly outer worldly to me

so my idea of "why not just use systemd to start this as a service at boot" got subsumed into "this is different, just google for what they say and go with it".

but you are on the face of it right it should be started as a systemd service.
Much simpler.

if off the top of your head you have a few lines to get rid of pm2 and set node red as a boot service that would be useful. Otherwise it will be a task for sometime soon.

No idea about PM2, sorry. Perhaps you can just uninstall it. The systemd script I pointed to (nodered.service) should be what you want. You should just need to setup the user and folder at the start for how you want (which is normally done by the install script of course, just one more bit of complexity).
On why you can't run the script I thought that was down to you having something odd about your nodejs install (you seemed to have installed two versions somehow I thought). If you have sorted that out then the install script should work. Maybe best to make an up to date backup image backup of the card before you try that though, if you haven't already.

thanks, I ran into a few issues with the script and gave up.
I think they posted above.

@Colin Thanks, it's now runnig as a systemd service
thanks for the tip

here is what got pm2 disabled and removed and node red set-up to start as a system service at boot


#####################################################################
############        remove pm2 and get node-red       ###############
############           to start as a service          ###############


# stop and disable the pm2-pi service
sudo systemctl stop    pm2-pi     # stop the pm2 service 
sudo systemctl disable pm2-pi     # disable it so it will not start at boot 
# sudo systemctl mask    pm2-pi     # service is now hidden unless unhidden


# uninstall pm2
sudo npm uninstall -g pm2


# change to correct directory to crate service unit
cd /lib/systemd/system



# create the service unit file

sudo bash -c "cat > nodered.service" << EOF
# 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=512"
# 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
EOF



# set the correct file permissions
sudo chmod 644 nodered.service




# make node red start as a service at boot
sudo systemctl enable  nodered    # make sure the service starts at boot


# start node red as a service
sudo systemctl start   nodered    # start the service now



# reboot and check everything works
reboot




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