Troubleshooting
Why Node-RED crashes at boot with EACCES mkdir //pki on a Linux PLC
Short answer
Keep the init.d script — it starts Node-RED correctly. The crash is an uncaught EACCES from the OPC UA client's mkdir of '//pki', a root-level directory the boot-time account cannot write, so fix the service user, HOME, working directory and certificate path instead. The camera's EHOSTUNREACH is a separate reachability fault that never kills the runtime.

On this page
- Is the init.d script failing to start Node-RED?
- Why can't the OPC UA client create its certificate directory?
- Why does the same Node-RED run fine when you start it by hand?
- What must the init script set before it launches Node-RED?
- Is EHOSTUNREACH 192.168.1.46:80 part of the same crash?
- Should you replace init.d with systemd or PM2?
- When should the IIoT flows move off the PLC?
- Questions asked
Your init.d script is innocent, and so is the absent systemd. The boot log shows Node-RED starting, running for about a minute, then dying on a single uncaught exception: EACCES: permission denied, mkdir '//pki', thrown by the OPC UA client bundled in node-red-contrib-iiot-opcua. The boot-started process tried to create a certificate directory at the filesystem root with no write access there; your manual launch survives because a terminal login supplies the user, home and working directory the script does not. Fix the environment the script hands Node-RED, keep the startup mechanism, and treat the camera's EHOSTUNREACH as a separate reachability fault.
Is the init.d script failing to start Node-RED? #
No — the boot log shows Node-RED starting and running for about a minute before the process dies, so the script launches the runtime correctly, and the fault happens after launch, inside the OPC UA nodes.
Read the log from a boot-driven start, not from your working manual session. The decisive lines:
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)
Classify before you change anything:
| Log evidence | What it proves | Next step |
|---|---|---|
| Startup banner, then normal running | The script starts the runtime; the fault follows launch | Read to the final exception |
[red] Uncaught Exception: ending in the mkdir refusal |
The OPC UA client's file operation kills the whole process | Fix the boot context, next two sections |
| EHOSTUNREACH from the camera request | One destination is unreachable at that moment | Separate reachability check |
| Manual start stays up | The interactive environment lets the same code succeed | Diff the two environments |
On this controller — an AXC F 2152 from Phoenix Contact, running Node.js 10.15.3 and Node-RED 0.20.5, with no systemd installed — the log is the first decision point, and it says the startup mechanism already works.
Why can't the OPC UA client create its certificate directory? #
Because //pki collapses on Linux to a top-level directory beside /bin and /etc, and the account the init script runs Node-RED as has no write permission at the filesystem root: the kernel answers the mkdir with EACCES, and nothing in node-red-contrib-iiot-opcua catches it.
The failing call sits in the bundled OPC UA client. _verify_serverCertificate in the node-opcua-client package's client_base.js calls Object.mkdirSync to make sure the certificate folder exists before it inspects the server certificate; the refusal propagates as an uncaught exception, and Node-RED exits with every flow on the instance.
The error also tells you the service account's privilege level. Run ls -ld / on the controller; a stock root directory reads drwxr-xr-x 1 root root. Decode it: owner root gets rwx, 4 + 2 + 1 = 7; group root gets r-x, 4 + 0 + 1 = 5; every other account gets r-x = 5. Mode 755 hands no write bit to any non-root user, so that account's mkdir beside /etc fails with EACCES — the logged line exactly. Root ignores those bits, so the log itself proves the script already runs Node-RED unprivileged. Keep that account, and never add write bits at the filesystem root to make the error pass; move the store instead.
Where the path is chosen: the store location comes from the OPC UA nodes' certificate settings or the client package's default, and the same client stack keeps its certificates in a folder of its certificate-manager package, so wherever it resolves, the service account must own it or be able to write it. Set the certificate folder to an absolute path under that account's home and create it with mode 700 before the next boot. A certificate that exists but is missing or rejected at deploy time is a different fault: see why a Node-RED deploy crashes on a missing OPC UA certificate.
Why does the same Node-RED run fine when you start it by hand? #
Because a terminal login hands Node-RED a real environment — your user id, a home directory, a working directory inside it, and a PATH that finds node — while the init script runs the same flows under a different identity with none of that context.
An init script starts with a minimal environment: the working directory is typically /, HOME is often unset or /, and PATH may not include where node lives. Same flows, different world. Diff the two launches on these readings:
| Reading | How the boot start breaks | What the script must set |
|---|---|---|
id — user and group |
Certificate and log folders belong to another account | The service account |
pwd — working directory |
Relative defaults resolve from / instead of a home |
The account's home directory |
echo $HOME |
The client's default store lands at the filesystem root | HOME for that account |
command -v node |
The script finds no node, or a different one | The absolute installed path |
| Log destination | The account cannot record its own startup failures | A writable log file |
Record each reading once from your working manual session and once from the script's own process; the differences are the fix list, and the next section is that list.
What must the init script set before it launches Node-RED? #
Five things, set explicitly: the service account, that account's HOME, a real working directory, absolute executable paths, and a writable log — plus the LSB header already in place, which orders the start after the local file systems and the network.
- Start Node-RED as the service account, switching with the init system's normal run-as tooling (
suorstart-stop-daemon), not as root. If a root start is unavoidable, Node-RED's own boot documentation requires the--userDiroption so its settings directory is declared rather than assumed. - Export HOME for that account and change into its home directory before the launch, so relative defaults stay inside it.
- Call node and the Node-RED entry point by absolute path — the ones your manual run proved.
- Send stdout and stderr to a log file that account can write.
- Keep the header as it is:
Required-Start: $local_fs $remote_fs $networkandDefault-Start: 2 3 4 5are correct for this controller, which has no systemd to migrate to.
Confirm nothing else launches a second copy at boot: if the firmware or an earlier attempt left another startup entry behind, remove it with the steps for disabling a pre-installed Node-RED startup on an edge PC.
Then prove the environment before the next reboot:
# run as the account the script uses, from the directory it starts in
id
pwd
echo "$HOME"
command -v node # must resolve to the Node.js 10.15.3 install
Finally, start it with the script's own start command — not from your shell — and watch the log through one full connect cycle. Pass: the OPC UA client connects and no new Uncaught Exception line appears. Fail: the same EACCES on a new path, which means the certificate folder setting itself still points somewhere that account cannot write.
Is EHOSTUNREACH 192.168.1.46:80 part of the same crash? #
No — that line comes from the http request node named Load JPG image from axis, is logged as an ordinary node error, and leaves the runtime alive; only the uncaught exception from the certificate mkdir ends the process.
The two errors share a timestamp, not a cause. Work the camera fault on its own:
- The PLC's own interface and its route toward the camera at the moment of the error. The header's
$networkordering covers the controller's stack, not the camera's readiness. - A ping from the PLC to the camera once boot settles. No answer points at the link, the address or the camera's power.
- The camera's web service. An answered ping with the request still failing moves the question to port 80 on the camera.
A destination that has no route at boot and answers a few minutes later is a device still starting; delay or retry the request in the flow rather than touching the startup script.
Should you replace init.d with systemd or PM2? #
No: in this case systemd is not installed on the controller and installing it did not succeed, and PM2 would only change who launches Node-RED — the same uncaught exception would still end the runtime under any manager.
The evidence for keeping the script is in its own header. The BEGIN INIT INFO block follows the LSB init-script convention: it declares what the script provides (node-red), the facilities that must be up first ($local_fs $remote_fs $network), and the runlevels where it starts (2 3 4 5). That header is doing its job — the process starts, every boot, after the network stack.
Decision: keep init.d, and spend the effort on the environment the script hands Node-RED. Before any future package work on this controller, follow the habit of identifying the Linux base before a native Node-RED install, because the base decides which init system and which Node.js you actually get.
When should the IIoT flows move off the PLC? #
When the pinned runtime blocks you: here Node.js 10.15.3 with Node-RED 0.20.5 is what the controller's package source installs by default, so once the nodes you need, or your patch cadence, outgrow that pair, run the gateway role on a separate edge box and leave control on the PLC.
The trade is simple. On the PLC you accept the runtime the firmware ships, and the fix above keeps it alive; off the PLC you choose the Node.js version, the Node-RED release, the node packages and the update schedule yourself. Keep real-time control and the OPC UA server on the controller, and when the workload outgrows it, run the flows on a fanless mini PC mounted beside it as the gateway.
On that gateway the certificate store lives under an ordinary service account with a real home directory, so this whole class of boot-context crash disappears — and the PLC keeps serving data over its industrial protocols.
Questions asked
Can a catch node stop this crash?
No. A catch node handles errors thrown by nodes inside a flow; this exception escapes the flow engine as an uncaught exception, and Node-RED exits before any catch scope can run. That is why every flow on the instance stops, not only the OPC UA one. The fix has to be environmental — a writable certificate path for the service account — not a flow change.
Why does the crash come about a minute after boot?
Node-RED loads and deploys the flows first; the OPC UA client only reaches certificate verification when its node first tries to connect to the server, and that attempt comes after startup. So the runtime looks healthy until the client walks into the mkdir call, roughly a minute in. A manual start hides the whole sequence because its environment lets the same call succeed.
Does EHOSTUNREACH mean the camera's IP address is configured wrong?
Not necessarily. EHOSTUNREACH means no usable route to that host at that moment: the PLC's interface may still be coming up during boot, the route may be missing, or the camera may still be starting. Ping the camera from the PLC once boot settles. An answered ping while the request still fails points at the camera's web service or its HTTP port instead.
What does the OPC UA client keep in its certificate folder?
Its own key pair with a self-signed client certificate, plus a copy of each server certificate it has seen, sorted into trusted and rejected. That is why the folder must be writable on first connect and must survive reboots: a store that resets forces the client to generate new keys, and the server may then reject the new client certificate until an operator trusts it again.
