Monday, 3 December 2012

[Supervisor] How to Monitor your program

Description
Supervisor is a great program that takes care about the healthy of your application.
The main feature is to monitor your application and then if something happens e.g. crash, it will restart the program.
There is a web interface where you can check the healthy of your programs and check uptime and logs, also you can stop/restart the process.

Installing

The follow command is to install supervisor on your Ubuntu/Debian machine:

sudo apt-get install supervisor

Configuration
The configuration file is located on your etc folder, I found it into /etc/supervisor/supervisor.conf on my Ubuntu.

You can easier add your applications to the file, just following the guide at this link, but I can give you some advice to configure it.
Each application that you want to monitor have to start with this header:
[program:name_your_application]

Add your path where the application is:
command=/bin/cat

and the process name

process_name=%(program_name)s


after that you are ready to restart your supervisor and it should start the process, just check it with "ps aux".
If everything is fine, continue to add more features, otherwise go back and check what is wrong.

These are helpful settings that you should have on your process that makes it alive even if it crashes
autostart=true
autorestart=true
startsecs=10 
startretries=3 

Also add some settings to save all logs from your application:
stdout_logfile=/a/path
stderr_logfile=/a/path

After that, restart your supervisor and everything should be fine.

Enable Web Interface
Usually the web interface is not enabled by default but you can do it , just adding these 3 lines on your configuration file

[inet_http_server]
port = 127.0.0.1:9001
username = user
password = 123

No comments:

Post a Comment