# Re: Feature request: Run a script when upstream detected down/up

**URL:** <https://www.ruby-forum.com/t/re-feature-request-run-a-script-when-upstream-detected-down-up/136118>\
**Category:** NGINX\
**Created:** [April 29, 2008, 3:26am UTC](https://www.ruby-forum.com/t/re-feature-request-run-a-script-when-upstream-detected-down-up/136118 "2008-04-29T03:26:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [April 29, 2008, 3:26am UTC](https://www.ruby-forum.com/t/re-feature-request-run-a-script-when-upstream-detected-down-up/136118/1 "2008-04-29T03:26:32Z")

</div>

> > Except that Nginx is asynchronous, not threaded. This means that when  
> > your script is called, Nginx will now be delayed while the script is  
> > launched (and what if the script fails?).

> Nginx will just have to wait until fork returns.

I don’t know much about this stuff, but isn’t there a way to fork  
something as a background process? Something equivalent to me typing  
“./my\_failover\_script &” ? So assuming nginx could simply make a shell  
system call or somehow make the call but tell it to run in the  
background, then I imagine the nginx thread that would call out to run  
the script would return almost immediately. At any rate, even if it  
took a little time, this should be a rare event, like maybe once every  
few weeks if things are running smoothly.

And if it can’t be launched as a background process, I would simply make  
the script it calls do something like flag another process to run, and  
then exit immediately so the thread returned quickly. The main thing is  
that I just need nginx to signal me somehow when it takes an upstream  
server out of rotation. Doing this by sniffing the log file is a hack  
at best.

> For the OP, executing a script when a backend fails is trivial, it  
> should be possibile to do it just be adding a new module.

Yes I had a look at the tutorial on building modules. Unfortunately it  
is over my head. This is why I am hopeful that the developers will  
recognize the importance of such a “hook” to an external monitoring  
system would be very useful especially if it is straight-forward to do.  
Thank you.

```
  ____________________________________________________________________________________

```

Be a better friend, newshound, and  
know-it-all with Yahoo! Mobile. Try it now.  
[http://mobile.yahoo.com/;\_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ](http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ)

---

<div class="post-metadata">

**Author:** ![Rt\_Ibmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@Rt\_Ibmer](https://www.ruby-forum.com/u/Rt_Ibmer)\
**Post date:** [April 29, 2008, 10:34am UTC](https://www.ruby-forum.com/t/re-feature-request-run-a-script-when-upstream-detected-down-up/136118/2 "2008-04-29T10:34:33Z")

</div>

Rt Ibmer ha scritto:

> > > Except that Nginx is asynchronous, not threaded. This means that when  
> > > your script is called, Nginx will now be delayed while the script is  
> > > launched (and what if the script fails?).
> 
> > Nginx will just have to wait until fork returns.
> 
> I don’t know much about this stuff, but isn’t there a way to fork something as a background process? Something equivalent to me typing “./my\_failover\_script &” ? So assuming nginx could simply make a shell system call or somehow make the call but tell it to run in the background, then I imagine the nginx thread that would call out to run the script would return almost immediately. At any rate, even if it took a little time, this should be a rare event, like maybe once every few weeks if things are running smoothly.
> 
> And if it can’t be launched as a background process, I would simply make the script it calls do something like flag another process to run, and then exit immediately so the thread returned quickly. The main thing is that I just need nginx to signal me somehow when it takes an upstream server out of rotation. Doing this by sniffing the log file is a hack at best.

There are no problems at spawing an external process.  
Simply, Nginx does not directly support this and you will get a lot of  
NOTICE messages in the log when each process exits (even if it exits  
with a success status code).

> > For the OP, executing a script when a backend fails is trivial, it  
> > should be possibile to do it just be adding a new module.
> 
> Yes I had a look at the tutorial on building modules. Unfortunately it is over my head. This is why I am hopeful that the developers will recognize the importance of such a “hook” to an external monitoring system would be very useful especially if it is straight-forward to do. Thank you.

Personally I’m not interested in this feature, sorry.  
I have given a look in the Nginx source code and it seems that all you  
want is implementable, and it should require only a few hours of coding.

Regards Manlio P.
