Discussion:
[Supervisor-users] Monitoring a process with supervisord and shell script/curl test
Mikko Ohtamaa
2015-02-06 09:49:15 UTC
Permalink
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?
--
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000
Marcos Cano
2015-02-06 18:35:41 UTC
Permalink
i would recommend Monit
Post by 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?
--
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000
_______________________________________________
Supervisor-users mailing list
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Jonathan Stewmon
2015-02-06 18:50:53 UTC
Permalink
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
Post by 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?
--
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000
_______________________________________________
Supervisor-users mailing list
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.
Mikko Ohtamaa
2015-02-06 21:48:13 UTC
Permalink
Hi,


If you're going to have a single server process command and a single check,
Post by Jonathan Stewmon
then you could just have supervisor keep both running and use a shell
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



...
Andres Reyes Monge
2015-02-06 21:51:56 UTC
Permalink
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
Post by Jonathan Stewmon
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
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
https://lists.supervisord.org/mailman/listinfo/supervisor-users
Jonathan Stewmon
2015-02-06 21:56:05 UTC
Permalink
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
Post by Andres Reyes Monge
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
Post by Jonathan Stewmon
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
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
https://lists.supervisord.org/mailman/listinfo/supervisor-users
_______________________________________________
Supervisor-users mailing list
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.
Mikko Ohtamaa
2015-02-06 21:58:00 UTC
Permalink
Post by Jonathan Stewmon
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
Jonathan Stewmon
2015-02-06 21:59:32 UTC
Permalink
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.
Post by Jonathan Stewmon
As Andres suggested, you could guard the curl call in the check script
Post by Jonathan Stewmon
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
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.
Gustavo Carneiro
2015-02-06 22:37:38 UTC
Permalink
Post by 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.
Even simpler: you can easily obtain the PID by calling: supervisorctl pid
programname
Post by Jonathan Stewmon
Post by Jonathan Stewmon
As Andres suggested, you could guard the curl call in the check script
Post by Jonathan Stewmon
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
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
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
Mikko Ohtamaa
2015-02-07 05:39:30 UTC
Permalink
Post by Gustavo Carneiro
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.
Post by Gustavo Carneiro
Post by Jonathan Stewmon
Post by Jonathan Stewmon
As Andres suggested, you could guard the curl call in the check script
Post by Jonathan Stewmon
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
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
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
https://lists.supervisord.org/mailman/listinfo/supervisor-users
--
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000
Loading...