# Unit file nodered.service does not exist

**URL:** <https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271>\
**Category:** General\
**Created:** [17 July 2020 17:32 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271 "2020-07-17T17:32:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 July 2020 17:32 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/1 "2020-07-17T17:32:31Z")

</div>

I'm trying to deploy node-red automatically via ansible,

I got everything up to the point I want with installing node-red via the script provided at [https://nodered.org/docs/getting-started/raspberrypi](https://nodered.org/docs/getting-started/raspberrypi)

But when I try to run the command:  
`sudo systemctl enable nodered.service`

I get an error:  
`Failed to enable unit: Unit file nodered.service does not exist.`

This errors on ansible side, and I have a deployed server with node-red installed, but not running.

My goal is to have node-red run after deploy and stay running (hopefully as a service as suggested by @knolleary )

Update: I'm trying to auto run this as the `ubuntu` user

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 July 2020 17:39 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/2 "2020-07-17T17:39:43Z")

</div>

Would anyone suggest I reimplement PM2 or stick with the services method?

[https://nodered.org/docs/faq/starting-node-red-on-boot](https://nodered.org/docs/faq/starting-node-red-on-boot)

---

<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:** [17 July 2020 17:52 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/3 "2020-07-17T17:52:52Z")

</div>

No, stick with systemd. You have to download the service file and the other scripts, look at the Pi install script to see where they are.

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 July 2020 19:23 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/4 "2020-07-17T19:23:11Z")

</div>

Ok, I see I have node-red being installed via npm:  
`npm install -g --unsafe-perm node-red node-red-admin`  
One issue I had with installing node-red via ansible using the script was the prompting for Y / N, but I now see there are command line options to automate these. Will try that and see if the script can get everything I need, if so, it should be OK with the `systemctl` service creation.

---

<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:** [17 July 2020 19:41 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/5 "2020-07-17T19:41:49Z")

</div>

I didn't mean to use the installation script, I meant to look there to see where the files you need are. This should do it

```auto
- name: Install node-red
  become: yes
  npm:
    name: node-red
    global: yes
    unsafe_perm: yes
      
- name: Download scripts
  become: yes
  get_url:
    owner: root
    mode: '755'
    url: "https://raw.githubusercontent.com/node-red/linux-installers/master/resources/{{ item }}"
    dest: "/usr/bin/{{ item|basename }}"
  with_items:
    - node-red-start
    - node-red-stop
    - node-red-restart
    - node-red-reload
    - node-red-log
    
- name: check if nodered.service exists
  stat: 
    path: /lib/systemd/system/nodered.service
  register: nodered_service
  
- name: Download nodered.service
  become: yes
  get_url:
    owner: root
    mode: '644'
    force: no
    url: "https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service"
    dest: "/lib/systemd/system/nodered.service"
  when: nodered_service.stat.exists == False
  
- name: Configure user in nodered.service
  become: yes
  block:
    - name: user
      lineinfile:
        path: /lib/systemd/system/nodered.service
        regexp: 'User='
        line: "User={{ansible_env.USER}}"
    
    - name: group
      lineinfile:
        path: /lib/systemd/system/nodered.service
        regexp: 'Group='
        line: "Group={{ansible_env.USER}}"
    
    - name: home
      lineinfile:
        path: /lib/systemd/system/nodered.service
        regexp: 'WorkingDirectory='
        line: "WorkingDirectory={{ansible_env.HOME}}"
    
- name: Reload systemd
  become: yes
  systemd:
    daemon_reload: yes

```

---

<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:** [17 July 2020 20:26 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/6 "2020-07-17T20:26:46Z")

</div>

There is also a slightly more feature-rich version of a service file in my alt-installer.

> **[TotallyInformation/alternate-node-red-installer](https://github.com/TotallyInformation/alternate-node-red-installer)**
>
> An alternative installer for Node-RED. Avoids global installs, no admin rights required. - TotallyInformation/alternate-node-red-installer

Which may also give you some ideas about not having to do a global install from Ansible.

---

<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:** [31 July 2020 20:26 UTC](https://discourse.nodered.org/t/unit-file-nodered-service-does-not-exist/30271/7 "2020-07-31T20:26:55Z")

</div>

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