[Supervisor-users] Monitoring a process with supervisord and shell script/curl test

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Mikko Ohtamaa
Hi,

I'd like to perform a HTTP POST request to a process under supervisord control. If the HTTP POST times out, or returns bad response, the process is restarted by supervisord.

This would be like httpok superlance module, but with some more logic - enable HTTP POST and post payload.

The easiest option I was thinking would be just run a arbitrary shell script command and based on the exit code of this script make the supervisord to restart the process. In my case the shell script would use curl + some logic to make the HTTP POST.

However I did not found any examples of supervisord and shell script checks. Do supervisord have support for them? Any alternatives for my use case?


--

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Marcos Cano
i would recommend Monit

On Fri, Feb 6, 2015 at 3:49 AM, Mikko Ohtamaa <[hidden email]> wrote:
Hi,

I'd like to perform a HTTP POST request to a process under supervisord control. If the HTTP POST times out, or returns bad response, the process is restarted by supervisord.

This would be like httpok superlance module, but with some more logic - enable HTTP POST and post payload.

The easiest option I was thinking would be just run a arbitrary shell script command and based on the exit code of this script make the supervisord to restart the process. In my case the shell script would use curl + some logic to make the HTTP POST.

However I did not found any examples of supervisord and shell script checks. Do supervisord have support for them? Any alternatives for my use case?


--

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users



_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Jonathan Stewmon
In reply to this post by Mikko Ohtamaa
If you're going to have a single server process command and a single check, then you could just have supervisor keep both running and use a shell script for the check. Something like this:

example supervisord.conf:

[program:myserver]
command=/your/server/command
process_name=%(program_name)s
numprocs=1
autostart=true
autorestart=true
priority=888
user=mikko

[program:mycheck]
command=/your/check.sh
process_name=%(program_name)s
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=true
user=mikko

example /your/check.sh:

while 1; do
if curl -f -X POST --connect-timeout=1 -m 1 -d 'post body' http://localhost/check
then
    sleep 60
else
    supervisorctl restart myserver
    sleep 60
fi

On Fri, Feb 6, 2015 at 3:49 AM, Mikko Ohtamaa <[hidden email]> wrote:
Hi,

I'd like to perform a HTTP POST request to a process under supervisord control. If the HTTP POST times out, or returns bad response, the process is restarted by supervisord.

This would be like httpok superlance module, but with some more logic - enable HTTP POST and post payload.

The easiest option I was thinking would be just run a arbitrary shell script command and based on the exit code of this script make the supervisord to restart the process. In my case the shell script would use curl + some logic to make the HTTP POST.

However I did not found any examples of supervisord and shell script checks. Do supervisord have support for them? Any alternatives for my use case?


--

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




This e-mail, including attachments, contains confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. The reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.
_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Mikko Ohtamaa
Hi,


If you're going to have a single server process command and a single check, then you could just have supervisor keep both running and use a shell script for the check. Something like this:


 
Thanks for the answer! One more question - what would be the correct way to check if the process myserver has been intentionally stopped (e.g. it is not in running state according to supervisorctl) - as this functionality is what httpok module provides also. It does not try to restart processes which have been taken down intentionally (e.g. for the duration of migration). Or does the config already do it somehow - and I don't manage to spot it?
 
while 1; do
if curl -f -X POST --connect-timeout=1 -m 1 -d 'post body' http://localhost/check
then
    sleep 60
else
    supervisorctl restart myserver
    sleep 60
fi



...

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Andres Reyes
I would have process create a pidfile on start and delete it on exit.

That way if the process doesn't exit successfully the pidfile will be there but the curl test will fail

Regards

On Fri Feb 06 2015 at 3:48:19 PM Mikko Ohtamaa <[hidden email]> wrote:
Hi,


If you're going to have a single server process command and a single check, then you could just have supervisor keep both running and use a shell script for the check. Something like this:


 
Thanks for the answer! One more question - what would be the correct way to check if the process myserver has been intentionally stopped (e.g. it is not in running state according to supervisorctl) - as this functionality is what httpok module provides also. It does not try to restart processes which have been taken down intentionally (e.g. for the duration of migration). Or does the config already do it somehow - and I don't manage to spot it?
 
while 1; do
if curl -f -X POST --connect-timeout=1 -m 1 -d 'post body' http://localhost/check
then
    sleep 60
else
    supervisorctl restart myserver
    sleep 60
fi



...
_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Jonathan Stewmon
As Andres suggested, you could guard the curl call in the check script with a condition for a pidfile existing.

For the specific case you asked about (doing a migration), you can stop the check using supervisorctl before you stop the server process:
supervisortctl stop mycheck
supervisorctl stop myserver
# perform maintenance
supervisorctl start myserver
supervisorcts start mycheck

On Fri, Feb 6, 2015 at 3:51 PM, Andres Reyes Monge <[hidden email]> wrote:
I would have process create a pidfile on start and delete it on exit.

That way if the process doesn't exit successfully the pidfile will be there but the curl test will fail

Regards

On Fri Feb 06 2015 at 3:48:19 PM Mikko Ohtamaa <[hidden email]> wrote:
Hi,


If you're going to have a single server process command and a single check, then you could just have supervisor keep both running and use a shell script for the check. Something like this:


 
Thanks for the answer! One more question - what would be the correct way to check if the process myserver has been intentionally stopped (e.g. it is not in running state according to supervisorctl) - as this functionality is what httpok module provides also. It does not try to restart processes which have been taken down intentionally (e.g. for the duration of migration). Or does the config already do it somehow - and I don't manage to spot it?
 
while 1; do
if curl -f -X POST --connect-timeout=1 -m 1 -d 'post body' http://localhost/check
then
    sleep 60
else
    supervisorctl restart myserver
    sleep 60
fi



...
_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




This e-mail, including attachments, contains confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. The reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.
_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Mikko Ohtamaa

As Andres suggested, you could guard the curl call in the check script with a condition for a pidfile existing.

Thanks!

Does supervisor provide functionality for pid file generation or do I just do it inside my app?

Cheers,
Mikko
 

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Jonathan Stewmon
If you go the pid file route, your server process will need to create the pid file when it starts and remove it when it exits.

On Fri, Feb 6, 2015 at 3:58 PM, Mikko Ohtamaa <[hidden email]> wrote:

As Andres suggested, you could guard the curl call in the check script with a condition for a pidfile existing.

Thanks!

Does supervisor provide functionality for pid file generation or do I just do it inside my app?

Cheers,
Mikko
 

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




This e-mail, including attachments, contains confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. The reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.
_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Gustavo Carneiro
On 6 February 2015 at 21:59, Jonathan Stewmon <[hidden email]> wrote:
If you go the pid file route, your server process will need to create the pid file when it starts and remove it when it exits.

Even simpler: you can easily obtain the PID by calling: supervisorctl pid programname


On Fri, Feb 6, 2015 at 3:58 PM, Mikko Ohtamaa <[hidden email]> wrote:

As Andres suggested, you could guard the curl call in the check script with a condition for a pidfile existing.

Thanks!

Does supervisor provide functionality for pid file generation or do I just do it inside my app?

Cheers,
Mikko
 

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




This e-mail, including attachments, contains confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. The reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




--
Gustavo J. A. M. Carneiro
Gambit Research
"The universe is always one step beyond logic." -- Frank Herbert

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Reply | Threaded
Open this post in threaded view
|

Re: [Supervisor-users] Monitoring a process with supervisord and shell script/curl test

Mikko Ohtamaa


Even simpler: you can easily obtain the PID by calling: supervisorctl pid programname

Thanks Gustavo! This is what I was after. I am in belief supervisor / systemd are taking over from more traditional, and sometimes problematic, PID files as more reliable service process management.
 


On Fri, Feb 6, 2015 at 3:58 PM, Mikko Ohtamaa <[hidden email]> wrote:

As Andres suggested, you could guard the curl call in the check script with a condition for a pidfile existing.

Thanks!

Does supervisor provide functionality for pid file generation or do I just do it inside my app?

Cheers,
Mikko
 

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




This e-mail, including attachments, contains confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. The reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




--
Gustavo J. A. M. Carneiro
Gambit Research
"The universe is always one step beyond logic." -- Frank Herbert

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users




--

_______________________________________________
Supervisor-users mailing list
[hidden email]
https://lists.supervisord.org/mailman/listinfo/supervisor-users