开发者

MySQL - start hook

I have a process which depends on MySQL, and cannot work without it. Is there a way to hook into MySQL such that I can trigge开发者_StackOverflow中文版r this process to restart every time MySQL restarts? Right now, I am manually restarting the process (which crashes when MySQL goes down) to bring it back up.


THere may be a way to "hook into mysql" to do this, but you don't need to. I'm going to assume you're running Linux or a UNIX variant, and that your instance of MySQL is listening on the default port (3306). Then the shell command:

netstat -an |grep 3306

will give you back a single line while the MySQL process is up, no output when it's down.

So write a Python script to run that command every T seconds and restart your process if it comes up empty, something like this:

#!/usr/bin/python
import time
import commands


while 1:
    if not commands.getoutput("netstat -an |grep 3306"):
        # restart your process
    time.sleep(10)

That ought to do it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜