How to listen for specific URL to restart Node red

I wish to trigger a restart of node red when I use this url on the node-red server, which is a rasp pi.

http://192.168.1.120:1880/node-red-restart

On the rasp pi, the node-red restart command is

cd /home/pi/.node-red; node-red restart

How do I get node-red to restart using a url in this way?

I have a "http in" node and an "execure node" with the flow as configured below.

[
    {
        "id": "b614769e.cfcf98",
        "type": "exec",
        "z": "5e66f20c.58838c",
        "command": "cd /home/pi/.node-red; sudo node-red restart",
        "addpay": false,
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "oldrc": false,
        "name": "node-red restart",
        "x": 660,
        "y": 420,
        "wires": [
            [],
            [
                "13381a54.0c6cc6"
            ],
            []
        ]
    },
    {
        "id": "38a70270.e1cfce",
        "type": "inject",
        "z": "5e66f20c.58838c",
        "name": "node-red restart",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "node-red restart",
        "payloadType": "str",
        "x": 160,
        "y": 420,
        "wires": [
            [
                "b614769e.cfcf98"
            ]
        ]
    },
    {
        "id": "87c92674.4d5518",
        "type": "http in",
        "z": "5e66f20c.58838c",
        "name": "node-red restart",
        "url": "http://192.168.1.120:1880/node-red-restart",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 160,
        "y": 480,
        "wires": [
            [
                "b614769e.cfcf98"
            ]
        ]
    },
    {
        "id": "13381a54.0c6cc6",
        "type": "debug",
        "z": "5e66f20c.58838c",
        "name": "node-red restart",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 420,
        "wires": []
    }
]

Does the command sudo node-red restart work in a terminal?
If not then how about the command sudo node-red-restart?

On the command line in the terminal
This does not work --> sudo node-red-restart
This does work --> sudo node-red restart

Are you sure? It should attempt to start node-red with a flows file called restart.json.
Did you use the recommended script for installing node-red on a pi? If so then you should have the commands
node-red-start
node-red-stop
node-red-restart

Hi,
I have an ARM 7, slightly older pi, and the install script just didn't work.
I gave up trying to use it after running into the second error it produced, and did a manual install.
That may explain why the hyphenated calls don't work.
But 'node-red restart' does work

Please post the log you get from running that command. Copy/paste the text please, using the </> button at the top of the forum text entry window when you paste it in.
Also tell us how you are running node-red normally (rather than a restart) and post the log from that.

pi@raspberrypi:~/.node-red $ node-red restart
7 Nov 17:19:37 - [info] 

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

7 Nov 17:19:37 - [info] Node-RED version: v1.2.2
7 Nov 17:19:37 - [info] Node.js  version: v12.19.0
7 Nov 17:19:37 - [info] Linux 5.4.72-v7+ arm LE
7 Nov 17:19:39 - [info] Loading palette nodes
7 Nov 17:19:45 - [info] Dashboard version 2.23.4 started at /ui
7 Nov 17:19:47 - [warn] ------------------------------------------------------
7 Nov 17:19:47 - [warn] [node-red-node-group/group] Error: This module is not required for Node-RED 1.1.0 or later (line:9)
7 Nov 17:19:47 - [warn] ------------------------------------------------------
7 Nov 17:19:47 - [info] Settings file  : /home/pi/.node-red/settings.js
7 Nov 17:19:47 - [info] Context store  : 'default' [module=memory]
7 Nov 17:19:47 - [info] User directory : /home/pi/.node-red
7 Nov 17:19:47 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Nov 17:19:47 - [info] Flows file     : /home/pi/.node-red/restart
7 Nov 17:19:47 - [info] Creating new flow file
7 Nov 17:19:47 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

7 Nov 17:19:47 - [info] Starting flows
7 Nov 17:19:47 - [info] Started flows
7 Nov 17:19:47 - [error] Unable to listen on http://127.0.0.1:1880/
7 Nov 17:19:47 - [error] Error: port in use
pi@raspberrypi:~/.node-red $
pi@raspberrypi:~/.node-red $ node-red-restart
-bash: node-red-restart: command not found
pi@raspberrypi:~/.node-red $

As you can see that just attempted to start node red again, with a flows file called restart, it has not stopped the one already running, which is why it cannot get access to the port.
Are you running node red as a systemd service? If so you can restart with
sudo systemctl restart nodered
Assuming your service file is nodered.service

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