# Catching events when a service ist stopped

**URL:** <https://discourse.nameko.io/t/catching-events-when-a-service-ist-stopped/174>\
**Category:** googlegroup\
**Created:** [March 16, 2017, 1:27pm UTC](https://discourse.nameko.io/t/catching-events-when-a-service-ist-stopped/174 "2017-03-16T13:27:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Fehl](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Andreas\_Fehl](https://discourse.nameko.io/u/Andreas_Fehl)\
**Post date:** [March 16, 2017, 1:27pm UTC](https://discourse.nameko.io/t/catching-events-when-a-service-ist-stopped/174/1 "2017-03-16T13:27:20Z")

</div>

Hi there,

I'm runnig several services in my cluster and i'd like to implement some  
kind of self monitoring. A dashboard should show what services are running,  
how many instances are out there and what are the hostnames.

So i need to emit an event when the service is stopped just to check out  
the service from the list.

How would you guys do that?

Thanks

Andreas

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [March 16, 2017, 5:32pm UTC](https://discourse.nameko.io/t/catching-events-when-a-service-ist-stopped/174/2 "2017-03-16T17:32:37Z")

</div>

The easiest way would be to add your own runner script, rather than using  
the `nameko run` CLI. Then you're free to do whatever you like before the  
services start, and after they stop.

Take a look  
at [https://github.com/nameko/nameko/blob/master/nameko/cli/run.py#L158-L181](https://github.com/nameko/nameko/blob/master/nameko/cli/run.py#L158-L181)  
for an example.

If I had this requirement I'd use something like consul to discover the  
available services though, rather than having to write a new runner.

> **···**
>
> On Thursday, March 16, 2017 at 1:27:20 PM UTC, Andreas Fehl wrote:
> 
> > Hi there,
> > 
> > I'm runnig several services in my cluster and i'd like to implement some  
> > kind of self monitoring. A dashboard should show what services are running,  
> > how many instances are out there and what are the hostnames.
> > 
> > So i need to emit an event when the service is stopped just to check out  
> > the service from the list.
> > 
> > How would you guys do that?
> > 
> > Thanks
> > 
> > Andreas

---

<div class="post-metadata">

**Author:** ![Andreas\_Fehl](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Andreas\_Fehl](https://discourse.nameko.io/u/Andreas_Fehl)\
**Post date:** [March 20, 2017, 1:30pm UTC](https://discourse.nameko.io/t/catching-events-when-a-service-ist-stopped/174/3 "2017-03-20T13:30:19Z")

</div>

Thank You for your quick reply.

I'll give both suggestions a try.

> **···**
>
> Am Donnerstag, 16. März 2017 18:32:37 UTC+1 schrieb Matt Yule-Bennett:
> 
> > The easiest way would be to add your own runner script, rather than using  
> > the `nameko run` CLI. Then you're free to do whatever you like before the  
> > services start, and after they stop.
> > 
> > Take a look at  
> > [https://github.com/nameko/nameko/blob/master/nameko/cli/run.py#L158-L181](https://github.com/nameko/nameko/blob/master/nameko/cli/run.py#L158-L181)  
> > for an example.
> > 
> > If I had this requirement I'd use something like consul to discover the  
> > available services though, rather than having to write a new runner.
> > 
> > On Thursday, March 16, 2017 at 1:27:20 PM UTC, Andreas Fehl wrote:
> > 
> > > Hi there,
> > > 
> > > I'm runnig several services in my cluster and i'd like to implement some  
> > > kind of self monitoring. A dashboard should show what services are running,  
> > > how many instances are out there and what are the hostnames.
> > > 
> > > So i need to emit an event when the service is stopped just to check out  
> > > the service from the list.
> > > 
> > > How would you guys do that?
> > > 
> > > Thanks
> > > 
> > > Andreas
