# Detect when a service/.exe stops running

**URL:** https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678
**Category:** General
**Created:** [25 October 2024 23:54 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678 "2024-10-25T23:54:02Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [25 October 2024 23:54 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/1 "2024-10-25T23:54:02Z")

</div>

Hi,  
So as the title says I am looking for a way to detect if a .exe (game server) or serice stops running. Ideally i'd like to make it so as soon as the app or service crashes it then triggers a node red flow but Im pretty sure that the app in question needs to send out the "I crashed signal" so that everything can process it (which these apps can't do). What would be the best way on Windows (primarily) and Ubuntu server to do this

---

<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: [26 October 2024 12:34 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/2 "2024-10-26T12:34:13Z")

</div>

You could use an exec node that runs a system command to test whether there is an appropriately named process running and test the result of that.

On linux you could us the `ps` command with appropriate parameters.

---

<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: [26 October 2024 14:41 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/3 "2024-10-26T14:41:54Z")

</div>

A cross-platform tool for observability is Telegraf. From the same people who make InfluxDB. While Telegraf works pretty seamlessly with InfluxDB (which I recommend for historic data anyway), you can also configure it to output to other endpoints. MQTT is ideal for use with Node-RED and I use this on my home automation server.

For Windows servers, you could also look at nodes that work with WMI.

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [26 October 2024 23:37 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/4 "2024-10-26T23:37:59Z")

</div>

So far in my testing I have been using `powershell ps` in an exec node and taking the error code into a switch which works pretty well, I was curious if there was a better way

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [26 October 2024 23:42 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/5 "2024-10-26T23:42:17Z")

</div>

Thanks for the info, I have tried using mosquitto but couldnt find a good setup guide that went from the start (espically for ubuntu server) and I was advised (On the Node Red slack) to go with websockets for simplicity (which they are easier), I just am not sure how to do it securely.

As for WMI I have no idea how I can use that as it seems like an enterprise style setup and im only doing this for a home setup

---

<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: [27 October 2024 00:15 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/6 "2024-10-27T00:15:24Z")

</div>

Clearly not relevant so deleted.

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [27 October 2024 00:17 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/7 "2024-10-27T00:17:27Z")

</div>

I just started the flow and this is what it looks like, I don't know if there is a way to delay start as there is no input to turn it on

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20ad529c57095d87853d02d668e4aa9d44412143.png)

---

<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: [27 October 2024 10:25 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/8 "2024-10-27T10:25:10Z")

</div>

> [@ath0rus](#):
>
> Thanks for the info, I have tried using mosquitto but couldnt find a good setup guide that went from the start (espically for ubuntu server) and I was advised (On the Node Red slack) to go with websockets for simplicity (which they are easier), I just am not sure how to do it securely.

I don't get time to peruse the Slack channel I'm afraid and I don't know why someone advised that. The basic install of Mosquitto is pretty trivial.

Setup for security is only really needed if your traffic is happening outside a single device. If both are running on the same device, you don't need to really worry about it. As you get to that point though, you will need a certificate which realistically means that you need a registered domain.

Any network traffic outside a single device should be encrypted for safety anyway though you might choose to ignore that on your home network if you are happy with the risk. You could use something like Tailscale to create your own virtual network with encrypted channels if you really can't get a certificate. Then you can treat that network as a local one.

WMI is generally for enterprises but it is just the Windows Management interface and is designed for managing devices and services both locally and remotely. Personally though, I'd go with Telegraf as that is relatively easy to learn and you can get your outputs in various ways.

Whichever way you look at it though, having Windows in the mix does make things a fair bit more complex. Linux is much easier to handle as a server.

I think that the thing you need to recognise is that observability requires you to understand a reasonable amount about how servers work and to learn some additional tooling. This may take some time but once done, is done and everything should just work.

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [27 October 2024 10:27 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/9 "2024-10-27T10:27:53Z")

</div>

> [@TotallyInformation](#):
>
> Setup for security is only really needed if your traffic is happening outside a single device. If both are running on the same device, you don't need to really worry about it. As you get to that point though, you will need a certificate which realistically means that you need a registered domain.

In the near future possibly needing to have 2 node instances communicate across the web, as for a domain registration that is fine as I already have one I use for game servers

---

<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: [27 October 2024 10:38 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/10 "2024-10-27T10:38:45Z")

</div>

I think that if you need the Internet involved, you should look at Tailscale as an option. It is designed for this kind of thing I think. I've not used it myself but there are other forum members who have. Indeed, one is writing a setup guide that I'm desperately trying to find time to review. 😄

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [27 October 2024 10:39 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/11 "2024-10-27T10:39:34Z")

</div>

If you can send me the link to it I may give it a go (when I have spare time) and give it a review/feedback at the end

---

<div class="post-metadata">

### Author: ![FireWizard52](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/firewizard52/32/34508_2.png) [@FireWizard52](https://discourse.nodered.org/u/FireWizard52)
#### Post date: [28 October 2024 15:58 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/12 "2024-10-28T15:58:26Z")

</div>

Hi

You asked:

> So as the title says I am looking for a way to detect if a .exe (game server) or serice stops running. Ideally i'd like to make it so as soon as the app or service crashes it then triggers a node red flow but Im pretty sure that the app in question needs to send out the "I crashed signal" so that everything can process it (which these apps can't do). What would be the best way on Windows (primarily) and Ubuntu server to do this

I use already for years "monit".  
See: [Easy, proactive monitoring of processes, programs, files, directories, filesystems and hosts | Monit](https://mmonit.com/monit/) and also [Bitbucket](https://bitbucket.org/tildeslash/monit/src/master/)  
Do not mix it with M/Monit, as this is a commercial implementation of Monit

Monit has its own webserver running on port 2812.

 ![Screenshot_monit](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b53cf774209bf4f016763722c01126d4f3b9ab5.png)

This will give you an overview of all processes running.  
Monit has also a simple API, which you can use with Node-RED.  
However, it is poorly documented.  
See: [http://Server](http://Server) IP address:2812/\_status?format=xml  
Username: "admin' and password "monit"

 ![Screenshot_monit-node-red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51eab80f9131659fdbb1ee87dae57ad6e7a26823.png)

```auto
[
    {
        "id": "0df294bbd75afd6a",
        "type": "inject",
        "z": "8087615b120096e1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 740,
        "y": 220,
        "wires": [
            [
                "8bb024ee56977530"
            ]
        ]
    },
    {
        "id": "8bb024ee56977530",
        "type": "http request",
        "z": "8087615b120096e1",
        "name": "",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.10.50:2812/_status?format=xml",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "basic",
        "senderr": false,
        "headers": [],
        "x": 930,
        "y": 220,
        "wires": [
            [
                "6f7f615db989d5f4"
            ]
        ]
    },
    {
        "id": "2c06f45a448fec6e",
        "type": "debug",
        "z": "8087615b120096e1",
        "name": "debug 300",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1290,
        "y": 220,
        "wires": []
    },
    {
        "id": "6f7f615db989d5f4",
        "type": "xml",
        "z": "8087615b120096e1",
        "name": "",
        "property": "payload",
        "attr": "",
        "chr": "",
        "x": 1110,
        "y": 220,
        "wires": [
            [
                "2c06f45a448fec6e"
            ]
        ]
    }
]

```

This is however only for Unix/linux systems

Regards

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [29 October 2024 07:07 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/13 "2024-10-29T07:07:07Z")

</div>

Thanks for that idea, I was hoping for an entierly Node red approach (with the possibility of the function node) too

---

<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: [29 October 2024 14:38 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/14 "2024-10-29T14:38:54Z")

</div>

Just because you have a hammer, not everything becomes a nail. 😉

---

<div class="post-metadata">

### Author: ![ath0rus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ath0rus/32/95404_2.png) [@ath0rus](https://discourse.nodered.org/u/ath0rus)
#### Post date: [3 November 2024 04:38 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/15 "2024-11-03T04:38:21Z")

</div>

I have made this which does what I want to do for the most part, Now to fine tune it over the next will and make it more efficent/smaller

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

---

<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: [1 February 2025 04:38 UTC](https://discourse.nodered.org/t/detect-when-a-service-exe-stops-running/92678/16 "2025-02-01T04:38:35Z")

</div>

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