# Impossible to make nodered start automatically at boot

**URL:** <https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245>\
**Category:** General\
**Created:** [14 June 2019 21:22 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245 "2019-06-14T21:22:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [14 June 2019 21:22 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/1 "2019-06-14T21:22:42Z")

</div>

Hello  
Itry to make nodered start at boot automatically.  
As I use node.js 10.15.3, and so, nodered 0.20.5, I can not use PM2 to make nodered start automatically.  
It seems that pm2 is not compatible with node.js 10.15.3

So, I followed an other way, using a file in init.d  
The full description of what I did is here 🙂

> <https://gist.github.com/SidMarc/11ed42b26da7b89c715da72746896240>

with this script, node-red starts at boot, but after a small minute, it crashes.  
Attached you will find the log of node-red startup, maybe you can tell me why it crashes.

But when i start node-red manually, with a simple command in the terminal, it works fine, without crashing.

you will se in the log file that for tha last startup, wich was manual, everything is fine.  
But in the before last start, node-red has been started by the init.d file, and after a while, it crashes.  
Do you see something in this log file that can tell you why NR crashes?  
[node-red.log.txt (99.7 KB)](https://discourse.nodered.org/uploads/short-url/zNS2Ca9wS89FkcXbGT7fayQvSSr.txt)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 June 2019 21:31 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/2 "2019-06-14T21:31:03Z")

</div>

> [@mike67](#):
>
> It seems that pm2 is not compatible with node.js 10.15.3

In what way?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4a0219e84b0a13efbdd89df54462c4af6b68bc9d.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 June 2019 21:32 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/3 "2019-06-14T21:32:51Z")

</div>

> [@mike67](#):
>
> So, I followed an other way, using a file in init.d

You need to tell us what platform you are using.

If it is a Raspberry Pi for example, and indeed most modern versions of Linux, you should be using systemd.

Dave's script for the Pi will set all of that up for you.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 June 2019 21:37 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/4 "2019-06-14T21:37:20Z")

</div>

> [@mike67](#):
>
> Do you see something in this log file that can tell you why NR crashes?

You are ignoring the very obvious error that is shown repeatedly in that log file.

In fact, you don't need to be messing with startup files as Node-RED is clearly trying to start but is crashing repeatedly.

```auto
29 May 21:44:37 - [error] [http request:Load JPG image from axis] Error: connect EHOSTUNREACH 192.168.1.46:80
29 May 21:44:37 - [red] Uncaught Exception:
29 May 21:44:37 - Error: EACCES: permission denied, mkdir '//pki'
    at Object.mkdirSync (fs.js:752:3)
    at _verify_serverCertificate (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/node-opcua-client/src/client_base.js:339:12)
    at /opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/node-opcua-client/src/client_base.js:624:13
    at /opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/node-opcua-client/src/client_base.js:248:9
    at /opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/async/dist/async.js:3888:9
    at /opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/async/dist/async.js:473:16
    at replenish (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/async/dist/async.js:1006:25)
    at iterateeCallback (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/async/dist/async.js:995:17)
    at /opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/async/dist/async.js:969:16
    at Immediate.<anonymous> (/opt/plcnext/appshome/data/60002172000051/lib/node_modules/node-red-contrib-iiot-opcua/node_modules/async/dist/async.js:3885:13)

```

Shows you quite clearly that a node is crashing Node-RED because it doesn't have access to a file that it wants.

In reality no node should do that as all file access should be wrapped such that errors are returned.

The problem lies with the node `node-red-contrib-iiot-opcua`. You should raise an issue on GitHub for that node.

I believe we have seen multiple issues with that node and it does seem to be causing issues. (apologies if I've confused it with something else).

---

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [15 June 2019 20:16 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/5 "2019-06-15T20:16:17Z")

</div>

Hello  
No this is not a rasp PI.  
It’s a PLC based on Linux on WICH it is possible to install any other thing based on Linux  
In the past the node.js version was something like 8.... now it is the new version that can be installed by default. But with the old version, NR could be started by PL2. Now the application diesn’t Start anymore.  
This is the reason why I wanted to find an other way.  
SystèmD is also not installed on my PLC.so Ican not use it . I tried to install it but unsuccessfully. If you have a good way to make it install correctly, tell me please,  
Thanks for your help

---

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [15 June 2019 20:17 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/6 "2019-06-15T20:17:37Z")

</div>

Hello  
After a while the errors related to the OPCUA IIOT DISAPPEAR, maybe just the time the device starts.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 June 2019 20:54 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/7 "2019-06-15T20:54:27Z")

</div>

What's this PLC make and model (I'm curious)?  
Perhaps search for the PLC make and model + start on boot. perhaps check see if they have forum you could ask on?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 June 2019 23:29 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/8 "2019-06-15T23:29:30Z")

</div>

> [@mike67](#):
>
> SystèmD is also not installed on my PLC.so Ican not use it . I tried to install it but unsuccessfully. If you have a good way to make it install correctly, tell me please,

Well, it seems to be using the older `init.d` which is similar but you will need to look up the correct syntax to get Node-RED to run on startup. Make sure you use the right user id to start Node-RED and don't assume that the environment variables are set so you may not have a PATH for example.

Also, don't forget that Node-RED probably needs at least the network to already be started. If you have any database nodes like MongoDB or MySQL, they will also need to be active before Node-RED starts as would the Mosquitto MQTT broker.

You are clearly getting a network error for example where `192.168.1.46:80` is unreachable..

---

<div class="post-metadata">

**Author:** ![mike67](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@mike67](https://discourse.nodered.org/u/mike67)\
**Post date:** [17 June 2019 05:59 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/9 "2019-06-17T05:59:51Z")

</div>

Hello Steve.

The PLc is an AXC F 2152, from Phoenix  
Contact.

This is a PLC of a new type.

In this PLc, wich natively supports  
industrial standards (Profinet, IEC 61131-3, Modbus TCP, etc...) is based  
on Linux.

It also supports high level languages  
by eclipse, visual studio, Matlab, etc...

Using nodeRed on this PLc opens it in  
a new way of interracting and programming with IIOT. And this is the reason  
why I make some tests with it.

You can find many details about this  
PLc [there](https://www.plcnext-community.net/index.php?lang=en).  
And about the PLC  
 itself. and its native programming  
[software](https://www.phoenixcontact.com/online/portal/ch/?uri=pxc-oc-itemdetail:pid=1046008&library=chfr&pcck=P-19-15-01&tab=1&selectedCategory=ALL).

Thanks for your help

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [17 June 2019 08:56 UTC](https://discourse.nodered.org/t/impossible-to-make-nodered-start-automatically-at-boot/12245/10 "2019-06-17T08:56:20Z")

</div>

At risk of jumping in with both feet...  
This used to be the old init script we used prior to systemd

> <https://github.com/node-red/raspbian-deb-package/blob/master/resources/nodered>

  
It probably needs some tweaks to make it fit for purpose (eg user and maybe --max-old-space-size)  
but should be a starting point
