Autostart Ubuntu 16.04 Problems?

I am trying to get Node-Red to start on boot on my NUC running Ubuntu 16.04. I am able to start using the simple node-red command, but any autostart option I try always fails. I have tried the recommend autostart guide, but that produces and status=1/FAILURE code. I have tried to use node-red-log, but it says command not found. I tried the pm2 version, but that seemed to install with errors because that seemed to indicate that I didn't have a high enough node version, it wanted 6 but said said I only had 4, even though I have 10.15 when I check node -v, so pm2 didn't work. I also tried one of the alternative systemd scripts, but got the same error as the recommend autostart. Any ideas how to get this autostart to work?

The node-red-log command does
sudo journalctl -f -n 25 -u nodered -o cat
so you can use that instead. Run it then, in a different terminal, run
node-red-start
If you still need help then post the result here.

Also, did you see the section "Changing the systemd environment - running as non-Pi user" in the link you posted?

Thanks, I'll run that log command and see what I get. And yes, I did change the user/group and working environment to be my user, so now its user=tc1, group=tc1 and workingenv=/home/tc1. Also, just as an update, I ran the Pi install script, i didn't receive any errors, but now when I try the autostart systemd I get exit code =127, which I believe is command not found?

if you ran the pi install script (as your tc1 user) then what does which node-red report ? and which node-red-start as they should both have been installed in /usr/bin.

Show us what you are entering to do that and what the full result is.
Running the pi install script will have set the systemd service to run as the user that you were logged in as when you ran the script.

which node-red returns /home/tc1/.nvm/versions/node/v10.15.3/bin/node-red
which node-red-start returns /usr/bin/node-red-start

the node-red command works fine and will start up node-red, the node-red-start up script is the one that produces the errors

@Colin when i run the node-red-start command (after I reload the daemon and enable the service) I get the following results (the journalctl command gives the same results):

Start Node-RED

Once Node-RED has started, point a browser at http:// 192.XXX.XX.XX:1880
On Pi Node-RED works better with the Firefox or Chrome browser

Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot

Starting as a systemd service.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Main process exited, code=exited, status=127/n/a
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Main process exited, code=exited, status=127/n/a
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Main process exited, code=exited, status=127/n/a
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
nodered.service: Main process exited, code=exited, status=127/n/a
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'exit-code'.
nodered.service: Service hold-off time over, scheduling restart.
Stopped Node-RED graphical event wiring tool.
nodered.service: Start request repeated too quickly.
Failed to start Node-RED graphical event wiring tool.
nodered.service: Unit entered failed state.
nodered.service: Failed with result 'start-limit-hit'.

In addition, if I run sudo systemctl status nodered.service i get:

nodered.service - Node-RED graphical event wiring tool
Loaded: loaded (/lib/systemd/system/nodered.service; enabled; vendor preset:
Active: failed (Result: start-limit-hit) since Mon 2019-04-22 21:42:49 EDT; 8
Docs: http:// nodered .org/docs/hardware/raspberrypi.html
Process: 6947 ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIO
Main PID: 6947 (code=exited, status=127)

Apr 22 21:42:49 NUC systemd[1]: nodered.service: Unit entered failed state.
Apr 22 21:42:49 NUC systemd[1]: nodered.service: Failed with result 'exit-code'.
Apr 22 21:42:49 NUC systemd[1]: nodered.service: Service hold-off time over, sch
Apr 22 21:42:49 NUC systemd[1]: Stopped Node-RED graphical event wiring tool.
Apr 22 21:42:49 NUC systemd[1]: nodered.service: Start request repeated too quic
Apr 22 21:42:49 NUC systemd[1]: Failed to start Node-RED graphical event wiring
Apr 22 21:42:49 NUC systemd[1]: nodered.service: Unit entered failed state.
Apr 22 21:42:49 NUC systemd[1]: nodered.service: Failed with result 'start-limit

You haven't shown us the journalctl command when you run node-red-start in another terminal. That is where the detail of the error will be.

You are using nvm. That runs as a script in user space. It does not affect the system environment so the version of node available to the system at boot time will be incorrect. If at all possible remove nvm and then reinstall using the script.

removing nvm via sudo rm -rf $NVM_DIR worked! The script works perfectly now, thank you @dceejay and @Colin!

1 Like