# Starting node-red at boot with systemctl

**URL:** <https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688>\
**Category:** General\
**Created:** [13 June 2024 23:15 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688 "2024-06-13T23:15:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)\
**Post date:** [13 June 2024 23:15 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/1 "2024-06-13T23:15:45Z")

</div>

I have installed node-red on Bookworm, RPI5. I can start it manually but cannot get it enabled with systemctl to start at boot.

> Blockquote

Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Failed with result 'exit-code'.  
Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Scheduled restart job, restart\>  
Jun 13 17:46:04 RPI5 systemd[1]: Stopped nodered.service - Node-RED graphical ev\>  
Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Start request repeated too qui\>  
Jun 13 17:46:04 RPI5 systemd[1]: nodered.service: Failed with result 'exit-code'.  
Jun 13 17:46:04 RPI5 systemd[1]: Failed to start nodered.service - Node-RED grap\>  
lines 1-14/14 (END)  
Any help would be appreciated. Thanks  
BG

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [13 June 2024 23:34 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/2 "2024-06-13T23:34:40Z")

</div>

For the sake of clarity:

How did you install Node-Red?  
What command did you use to _auto-start_ Node-Red?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 June 2024 23:42 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/3 "2024-06-13T23:42:52Z")

</div>

> [@bgrattan3](#):
>
> I can start it manually

Do you mean that `sudo systemctl start nodered` works, or you can start it with the `node-red` command?

After you reboot and it falls over, what does` journalctl -t Node-RED --since today --no-pager` output?

---

<div class="post-metadata">

**Author:** ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)\
**Post date:** [14 June 2024 21:05 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/4 "2024-06-14T21:05:37Z")

</div>

I am able to start it manually:

```auto
bg@RPI5:~ $ node-red
14 Jun 16:55:11 - [info]

Welcome to Node-RED
===================

14 Jun 16:55:11 - [info] Node-RED version: v3.1.10
14 Jun 16:55:11 - [info] Node.js version: v18.20.3
14 Jun 16:55:11 - [info] Linux 6.6.31+rpt-rpi-2712 arm64 LE
14 Jun 16:55:11 - [info] Loading palette nodes
14 Jun 16:55:12 - [info] Settings file : /home/bg/.node-red/settings.js
14 Jun 16:55:12 - [info] Context store : 'default' [module=memory]
14 Jun 16:55:12 - [info] User directory : /home/bg/.node-red
14 Jun 16:55:12 - [warn] Projects disabled : editorTheme.projects.enabled=false
14 Jun 16:55:12 - [info] Flows file : /home/bg/.node-red/flows.json
14 Jun 16:55:12 - [info] Creating new flow file
14 Jun 16:55:12 - [warn] Encrypted credentials not found
14 Jun 16:55:12 - [info] Server now running at http://127.0.0.1:1880/
14 Jun 16:55:12 - [info] Starting flows
14 Jun 16:55:12 - [info] Started flows

```

When I try to set it up to start at boot:

```auto
bg@RPI5:~ $ systemctl enable nodered
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ====
Authentication is required to manage system service or unit files.
Authenticating as: ,,, (bg)
Password:
==== AUTHENTICATION COMPLETE ====
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ====
Authentication is required to reload the systemd state.
Authenticating as: ,,, (bg)
Password:
==== AUTHENTICATION COMPLETE ====
bg@RPI5:~ $ service node-red status
Unit node-red.service could not be found.
bg@RPI5:~ $ service nodered status
× nodered.service - Node-RED graphical event wiring tool
     Loaded: loaded (/lib/systemd/system/nodered.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-06-14 14:31:17 EDT; 2h 16min ago
   Duration: 2ms
       Docs: http://nodered.org/docs/hardware/raspberrypi.html
   Main PID: 931 (code=exited, status=217/USER)
        CPU: 894us

bg@RPI5:~ $ journalctl -t Node-RED --since today --no-pager
-- No entries --

```

It seems to be installed but I can't enable it at boot. I'm not a programmer so am having trouble  
understanding what is going on. I use NR to send MQTT data from sensors to my weather station ([N4MRV-1 --- Ashland, Virginia Current Weather Conditions](http://grattans.org/wx)) which is now running on Ubuntu. I'm trying to move to a new server, RPI5 running Bookworm.  
Thanks.  
BG

---

<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:** [14 June 2024 21:24 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/5 "2024-06-14T21:24:49Z")

</div>

How about  
`journalctl -u nodered --since today --no-pager`

Also show us what is in `/lib/systemd/system/nodered.service`

---

<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:** [14 June 2024 21:39 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/6 "2024-06-14T21:39:05Z")

</div>

And what does  
node-red-start  
report ?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 June 2024 22:06 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/7 "2024-06-14T22:06:01Z")

</div>

I'm not familiar with that inline authentication method. On my Pies I use sudo  
`sudo systemctl enable nodered` or `sudo systemctl start nodered`

According to the internet, so it must be true 😆, error 217 means the service is setup with a username which does not exist.  
Please show us your /lib/systemd/system/nodered.service file.

If `journalctl -t Node-RED --since today --no-pager` shows no entries, please try  
`sudo systemctl restart nodered` and try again.

---

<div class="post-metadata">

**Author:** ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)\
**Post date:** [14 June 2024 22:59 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/8 "2024-06-14T22:59:47Z")

</div>

Ok, that did it. nodered.service had pi as user and I’m bg. Bookworm seems to boot and start NR correctly.  
Much appreciated for the help in figuring this out!!  
I may be back but this is a great start.  
Cheers,  
Bob

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 June 2024 23:17 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/9 "2024-06-14T23:17:27Z")

</div>

Can you explain how you installed Node-red, what username you used, and when you created the username bg?

Is your Node-red directory `/home/bg/.node-red` ?

The Raspberry Pi install script is certainly supposed to set up the service to run as the user who installs it, but there could still be a bug.

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [15 June 2024 05:13 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/10 "2024-06-15T05:13:55Z")

</div>

Much easer and safe is just install it in docker and write

```auto
restart: unless-stopped

```

in docker compose config, It is not really good idea to install things to host itself.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 June 2024 07:14 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/11 "2024-06-15T07:14:15Z")

</div>

Although I normally would somewhat agree with this statement - but for node-red it is definitely not always the best option, especially when interfacing with devices on hardware level as node-red will not have access to those, one will need to go through quite some hoops to make that work within docker. Some nodes need to compile binaries, there is no compiler included in the docker container (unless customized).

One might argue not to use docker for node-red at all.

---

<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:** [15 June 2024 08:02 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/12 "2024-06-15T08:02:35Z")

</div>

For those experienced in the use of Docker it can be very useful, for those without such experience I advise against using it for node-red. It causes more problems than it solves.

---

<div class="post-metadata">

**Author:** ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)\
**Post date:** [15 June 2024 14:25 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/13 "2024-06-15T14:25:30Z")

</div>

Hi jbudd,  
To install, I used:  
bash \<(curl -sL [https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered](https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered))

When I setup the RPI5, I did it as "bg." Not sure why and I probably should have used the default as "pi." Anyway, My .node-red directory is in /home/bg.  
Cheers,  
Bob

---

<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:** [15 June 2024 16:08 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/14 "2024-06-15T16:08:04Z")

</div>

If you were logged in as bg when you ran the script then it should have put bg as the user in the script. Are you sure you didn't run the script before you changed the user name?

> [@bgrattan3](#):
>
> When I setup the RPI5, I did it as "bg." Not sure why and I probably should have used the default

No, it is a good idea to _not_ use the default 'pi'. It slightly reduces the chance of being hacked.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [15 June 2024 16:23 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/15 "2024-06-15T16:23:40Z")

</div>

> [@zba](#):
>
> Much easer and safe is just install it in docker and write

For those who like/know docker (and similar environments) - indeed!

But I have to disagree with this statement, it is (IMO) by far NOT easier!  
especially for those getting into automation/Node RED and everything in between.

---

<div class="post-metadata">

**Author:** ![bgrattan3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bgrattan3/32/47488_2.png) [@bgrattan3](https://discourse.nodered.org/u/bgrattan3)\
**Post date:** [15 June 2024 18:27 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/16 "2024-06-15T18:27:11Z")

</div>

Colin,  
When I first installed the OS Bookworm on the RPI5 it was as “bg.” I never created user “pi” and don’t think it’s a valid user at this point. I hope this won’t cause later problems.  
Cheers,  
Bob

---

<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:** [15 June 2024 20:03 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/17 "2024-06-15T20:03:35Z")

</div>

> [@bgrattan3](#):
>
> I never created user “pi” and don’t think it’s a valid user at this point

Well that is very odd, there is definitely code in the install that sets the user and group to the current user. I presume that you just had to change the lines

```auto
User=pi
Group=i

```

Could you post that file please so I can see if there are any clues as to what might have happened? `/lib/systemd/system/nodered.service`. There haven't been any other reports of that not working though, as far as I know.

> [@bgrattan3](#):
>
> I hope this won’t cause later problems.

No, it shouldn't cause any problems. That is the only place the user is used.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [15 June 2024 20:36 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/18 "2024-06-15T20:36:33Z")

</div>

> [@Colin](#):
>
> I presume that you just had to change the lines ...

There are 4 lines with "pi" hardcoded in the systemd script as downloaded (/usr/lib/systemd/system/nodered.service)

```auto
User=pi
Group=pi
WorkingDirectory=/home/pi
EnvironmentFile=-/home/pi/.node-red/environment

```

The installer should have changed "pi" to the current username on all 4 lines.

---

<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:** [15 June 2024 21:09 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/19 "2024-06-15T21:09:37Z")

</div>

> [@jbudd](#):
>
> There are 4 lines with "pi" hardcoded in the systemd script as downloaded

Yes, you are right, I had forgotten the other two.

---

<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 September 2024 21:10 UTC](https://discourse.nodered.org/t/starting-node-red-at-boot-with-systemctl/88688/20 "2024-09-13T21:10:23Z")

</div>

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