# Node-RED won't run as service Debian 10

**URL:** https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558
**Category:** General
**Created:** [11 February 2020 18:40 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558 "2020-02-11T18:40:47Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![dtorres](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@dtorres](https://discourse.nodered.org/u/dtorres)
#### Post date: [11 February 2020 18:40 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/1 "2020-02-11T18:40:48Z")

</div>

Hello all, I installed Node-RED using the script, as I try to set it up to run as service I got an error.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c5aff1e2b55e5112d8f606c058841ee93bed75d.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2020 20:08 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/2 "2020-02-11T20:08:35Z")

</div>

If you run `node-red-start` it will start it using the service but then the log will appear. Alternatively you can look back in /var/log/syslog to the time 12:39 and you will see it there.

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [11 February 2020 20:47 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/3 "2020-02-11T20:47:50Z")

</div>

> [@Colin](#):
>
> If you run `node-red-start` it will start it using the service but then the log will appear.

Tip: `node-red-log` will just display that same tail of the log, and keep it updated as more comes in. However, since you're coming from a crashed state, `node-red-start` is the better option here. For future reference though 🙂

---

<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: [11 February 2020 20:59 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/4 "2020-02-11T20:59:51Z")

</div>

`sudo journalctl nodered` will show you the last few lines of the log, adding the `-f` (follow) parameter will keep the log showing.

I recommend starting another terminal window to show the log in realtime - that way you can see exactly what is happening.

I've just gone through all this on my new build - though I use my own service file with my alternate installer.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 February 2020 21:10 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/5 "2020-02-11T21:10:58Z")

</div>

> [@TotallyInformation](#):
>
> `sudo journalctl nodered`

That's what `node-red-log` does.

---

<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: [11 February 2020 21:14 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/6 "2020-02-11T21:14:55Z")

</div>

Ah, well I prefer to use native commands where possible - that way I also know how to show the logs for mosquitto, InfluxDB, Grafana, Telegraf, ... 😀

I guess I just like to know how things work!

---

<div class="post-metadata">

### Author: ![dtorres](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@dtorres](https://discourse.nodered.org/u/dtorres)
#### Post date: [12 February 2020 20:08 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/7 "2020-02-12T20:08:58Z")

</div>

Has anyone solved this error before?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af32ca4ed256728a725399122e225ca9b731881d.png)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 February 2020 20:35 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/8 "2020-02-12T20:35:10Z")

</div>

Can you post here the service file `/lib/systemd/system/nodered.service` please. Copy/paste if possible rather than a screenshot, it is easier to read.  
Did you run the install script as root by any chance? You should have run it logged in as the user you want to run node-red (which should not be root). If you did run it as root then I think you can just edit the service file and change the user, group and working directory. then run the `sudo systemctl daemon-reload` and try starting node-red again.

---

<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: [12 February 2020 23:55 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/9 "2020-02-12T23:55:22Z")

</div>

For reference, here is my custom service file on my new build:

```ini
# A TEMPLATE systemd service file for running Node-RED
# CHANGE the settings before use.
#
# See https://github.com/TotallyInformation/alternate-node-red-installer
# https://gist.github.com/Belphemur/3f6d3bf211b0e8a18d93
# http://www.freedesktop.org/wiki/Software/systemd/
#
# This file must be linked into the /etc/systemd/system/multi-user.target.wants/ folder:
# 1) Rename this file to have a unique name (in case you want other instances running)
# 2) sudo /bin/systemctl enable /home/<user>/<folder>/system/<filename>.service
# 3) sudo systemctl daemon-reload
#
# After installing or changing this file:
# 1) sudo systemctl daemon-reload
#
# Start manually with `sudo /bin/systemctl start <filename>`
# View logs with `sudo journalctl -u <filename>` (e.g. `sudo journalctl -u node-red`)
# View service status with `sudo systemctl status <filename>`

[Unit]
Description=Knightnet Home Automation System - Node-RED nrmain
Documentation=https://github.com/TotallyInformation/alternate-node-red-installer http://nodered.org/docs
# Syslog and Networking must be active before starting
After=syslog.target network.target
# Mosquitto (MQTT) & InfluxDB may be wanted - ADJUST to need
Wants=mosquitto.service influxdb.service

[Service]
Type=simple

# -- Set any required environment variables - ADJUST these according to your installation --
Environment="NODE_RED_OPTIONS=--userDir /home/home/nrmain/data -v"
Environment="NODE_OPTIONS= "
#Environment="NODE_OPTIONS=--max-old-space-size=128"

# Or use an environment variables file, overrides the Environment settings
# makes it nice and easy to change without having to edit this file.
# Ignored if file does not exist. Entries in file overwrite those above.
# @See https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=
EnvironmentFile=-/home/home/nrmain/data/envfile.ini

# No path environment variable is yet available here so make sure absolute folders specified
ExecStart=/usr/bin/node $NODE_OPTIONS /home/home/nrmain/node_modules/node-red/red.js $NODE_RED_OPTIONS

WorkingDirectory=/home/home/nrmain

# User/Group that launches node-RED (it's advised to create a new user for Node-RED)
# You can do : sudo useradd node-red then change the User=pi to User=node-red
# If changing the user/group, make sure that ALL FILES and FOLDERS have the correct
# ownership before continuing.
User=home
Group=home

Nice=10

SyslogIdentifier=NRMAIN
StandardOutput=syslog

# Make Node-RED restart if it fails
Restart=on-failure

#Restart=always
#RestartSec=100

# Node-RED needs a SIGINT to be notified to stop
KillSignal=SIGINT

# Prevent this service changing the OS or /etc
# @See https://www.freedesktop.org/software/systemd/man/systemd.exec.html#ProtectSystem=
ProtectSystem=full

# PID file
PIDFile=/home/home/nrmain/nrmain.pid

[Install]
WantedBy=multi-user.target

```

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [13 February 2020 06:43 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/10 "2020-02-13T06:43:46Z")

</div>

> [@TotallyInformation](#):
>
> PIDFile=/home/home/nrmain/nrmain.pid

Is that path correct? I see it repeated over the other variables so I think it is, although an unusual name it would make sense, but it can lead to confusion 🙂

---

<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: [13 February 2020 13:37 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/11 "2020-02-13T13:37:48Z")

</div>

Yes, correct. My own fault for choosing a default user name to match the purpose of the device! 🙀

Only me directly using the device though so not really an issue.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [13 February 2020 14:16 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/12 "2020-02-13T14:16:38Z")

</div>

This is what the standard Debian/pi install script installs (unless it has changed recently)

```auto
# 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=username
Group=username
WorkingDirectory=/home/username

Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=256"
# 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

```

---

<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: [13 February 2020 15:43 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/13 "2020-02-13T15:43:45Z")

</div>

Apart from running from a local install of Node-RED instead of a global one, the main difference in mine is the ability to override the environment vars and therefore the startup settings via a local file. It also requires syslog & networking along with Mosquitto and InfluxDB to be started first. Also I don't set max-old-space by default (because this was taken from the laptop build). Not sure if `ProtectSystem=full` actually does anything in this case but it seemed sensible.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [13 April 2020 15:43 UTC](https://discourse.nodered.org/t/node-red-wont-run-as-service-debian-10/21558/14 "2020-04-13T15:43:46Z")

</div>

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