n8n: start 3.x through a wrapper and with HOME=/root

Two things the test journal showed, both reproduced on Debian 13:

- n8n finds its modules with require.resolve('n8n/package.json'), which
  fails outside a node_modules tree, and then falls back to
  process.argv[1]/../../dist. Started through the /usr/local/bin/n8n
  symlink, that is /usr/local/dist, so every start died with
  MissingModuleError (policy-infrastructure) and systemd restarted it.
  /usr/local/bin/n8n is now a wrapper that runs node /opt/n8n/bin/n8n.
- Without HOME, n8n 3.x keeps its data in /.n8n: a 2.x install moved to
  3.x would have started on an empty database. The unit sets HOME=/root.
This commit is contained in:
Rögl-Brunner Michel committed 2026-11-17 12:32:21 +01:00
1 parent b6a12f84a7
commit bd8c84e64f
2 files changed
+20 -2

No files matched your search

+10 -1
View File
@@ -131,6 +131,8 @@ Wants=network-online.target
[Service]
Type=simple
Environment=NODE_ENV=production
# Without HOME, n8n 3.x keeps its data in /.n8n instead of /root/.n8n.
Environment=HOME=/root
EnvironmentFile=/opt/n8n.env
ExecStart=/usr/bin/env n8n start
Restart=on-failure
@@ -246,8 +248,15 @@ function install_n8n_image() {
cp -a "${N8N_BUNDLE}/usr/share/fonts/truetype/msttcorefonts" /usr/share/fonts/truetype/
fi
rm -rf "$N8N_BUNDLE"
# Not a symlink: n8n finds its modules from the path it was started as
# (process.argv[1]/../../dist), which must be /opt/n8n/bin/n8n.
mkdir -p /usr/local/bin
ln -sf /opt/n8n/bin/n8n /usr/local/bin/n8n
rm -f /usr/local/bin/n8n
cat <<'EOF' >/usr/local/bin/n8n
#!/bin/sh
exec node /opt/n8n/bin/n8n "$@"
EOF
chmod 755 /usr/local/bin/n8n
if ! /usr/local/bin/n8n --version 2>/dev/null | grep -qxF "$version"; then
msg_error "n8n ${version} does not start in this container."
exit 1
+10 -1
View File
@@ -113,8 +113,15 @@ if ((${N8N_VERSION%%.*} >= 3)); then
cp -a "${N8N_BUNDLE}/usr/share/fonts/truetype/msttcorefonts" /usr/share/fonts/truetype/
fi
rm -rf "$N8N_BUNDLE"
# Not a symlink: n8n finds its modules from the path it was started as
# (process.argv[1]/../../dist), which must be /opt/n8n/bin/n8n.
mkdir -p /usr/local/bin
ln -sf /opt/n8n/bin/n8n /usr/local/bin/n8n
rm -f /usr/local/bin/n8n
cat <<'EOF' >/usr/local/bin/n8n
#!/bin/sh
exec node /opt/n8n/bin/n8n "$@"
EOF
chmod 755 /usr/local/bin/n8n
if ! /usr/local/bin/n8n --version 2>/dev/null | grep -qxF "$N8N_VERSION"; then
msg_error "n8n ${N8N_VERSION} does not start in this container."
exit 1
@@ -150,6 +157,8 @@ Wants=network-online.target
[Service]
Type=simple
Environment=NODE_ENV=production
# Without HOME, n8n 3.x keeps its data in /.n8n instead of /root/.n8n.
Environment=HOME=/root
EnvironmentFile=/opt/n8n.env
ExecStart=/usr/bin/env n8n start
Restart=on-failure