开发者

Python daemonize

I would like to daemonize a python process, and now want to ask if it is good practice to have a daemon running, like a pa开发者_如何学Gorent process and call another class which opens 10-30 threads.

I'm planning on writing a monitoring script for group of servers and would like to check every server every 5 mins, that each server is checked exactly 5minutes.

I would like to have it this way ( sort of speak, ps auxf style output ):

|monitor-daemon.py
 \-check-server.py
 \-check-server.py

....

Thank you!


Maybe you should use http://pypi.python.org/pypi/python-daemon


You can use supervisord for this. You can configure tasks to respond to events. The events can be manually created or automatically by monitoring processes or based on regular intervals.

It is fully customizable and written in Python.

Example:

[program:your_daemon_name]
command=your_daemon_process
# Add extra options here according to the manual...

[eventlistener:your_monitor_name]
command=your_monitor_process
events=PROCESS_STATE_RUNNING # Will be triggered after a program changes from starting to running
# Add extra options here according to the manual...

Or if you want the eventlistener to respond to the process output use the event PROCESS_COMMUNICATION_STDOUT or TICK_60 for a check every minute. The logs can be redirected to files and such so you can always view the state.


There's really not much to creating your own daemonize function: The source for Advanced Programming in the Unix Environment (2nd edition) is freely available: http://www.apuebook.com/src.tar.gz -- you're looking for the apue.2e/daemons/init.c file.

There is a small helper program that does all the work of creating a proper daemon, it can be used to wrap arbitrary programs; this might save some hassle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜