Need to check if node is active

Hi, I'm trying to check if node-red is active and then, if not, restart it.

I'm using a switch to see if the msg is equal to "active".

Different debug messages should show how it's working, to be later replaced by an exec node with systemctl is-active nodered.service if not active.

Problem is that it's always going to otherwise, ie, it shows active in the NOK debug node.

[
    {
        "id": "af636deb.ad577",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": ""
    },
    {
        "id": "3ba95e02.cc67e2",
        "type": "inject",
        "z": "af636deb.ad577",
        "name": "check node",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 270,
        "y": 180,
        "wires": [
            [
                "5aabb621.491ff8"
            ]
        ]
    },
    {
        "id": "5aabb621.491ff8",
        "type": "exec",
        "z": "af636deb.ad577",
        "command": "systemctl is-active nodered.service",
        "addpay": false,
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "oldrc": false,
        "name": "check node",
        "x": 410,
        "y": 180,
        "wires": [
            [
                "513ef760.697368",
                "812ff0f1.e5137"
            ],
            [],
            []
        ]
    },
    {
        "id": "513ef760.697368",
        "type": "debug",
        "z": "af636deb.ad577",
        "name": "REPLY",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 600,
        "y": 140,
        "wires": []
    },
    {
        "id": "812ff0f1.e5137",
        "type": "switch",
        "z": "af636deb.ad577",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "active",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 590,
        "y": 180,
        "wires": [
            [
                "27f96e12.e4bad2"
            ],
            [
                "52096489.ac673c"
            ]
        ]
    },
    {
        "id": "27f96e12.e4bad2",
        "type": "debug",
        "z": "af636deb.ad577",
        "name": "OK",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 730,
        "y": 160,
        "wires": []
    },
    {
        "id": "52096489.ac673c",
        "type": "debug",
        "z": "af636deb.ad577",
        "name": "NOK",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 730,
        "y": 200,
        "wires": []
    }
]

Thanks in advance.

If you look at the debug node on the switch input you will see there is a CR on the end of the string, so it doesn't match that in the switch.

But you are using the standard systemd process to run Node-RED so the only time it wouldn't be active is if there is a serious problem and systemd used up all of the restarts defined? In that case, restarting it is probably not going to help as it would fail again unless you have changed something else.

CR? I've been trying to figure this out at this and I'm not following what you mean.

Yes, I figure as much.

There's no real issue here, I just want to have a bit of a failsafe.

I'm aware this won't solve every problem out there but I just want to make sure I can get it to reset in most cases.

OK, no problem.

In my own case, I occasionally have an issue with my Pi losing network access so I have a flow that actually reboots the Pi if network connectivity is lost.

I also have flows that provide heartbeat messages to MQTT for various services.

Carriage return. You can see it on the end of the string in the debug node.
However, I am confused. You are running this inside node-red, so if the service is not running then the flow won't run in the first place, so it won't be able to detect that is is not running. It is like telling someone to take their own pulse so they can tell if they are still alive.

Dang... got so caught up in what NR can do I forgot how to logic.

Guess I'll do this with some sort of script.

Thanks.