Hi, all

In a paas-like platform,  I need reload haproxy frequently, I use a python
script to reload the haproxy. Here is my test python script to reproduce
the issue:


#! /usr/bin/python

import subprocess
import logging
import thread
import time

HAPROXY_CONFIG_FILE = "/haproxy.cfg"
HAPROXY_RUN_COMMAND = ['/usr/sbin/haproxy', '-f', HAPROXY_CONFIG_FILE,
'-db', '-q']
logger = logging.getLogger("haproxy")

def wait_pid(process):
    process.wait()
    logger.info("HAProxy(PID:%s) has been terminated" % str(process.pid))

old_process = 9999

i = 0
while i < 100 :
        if old_process:
                # Reload haproxy
                logger.info("Reloading HAProxy")
                old_process = subprocess.Popen(HAPROXY_RUN_COMMAND +
["-sf", str(old_process)])
                thread.start_new_thread(wait_pid, (old_process,))
# time.sleep(0.1)
                logger.info("HAProxy has been reloaded(PID: %s)",
str(old_process))
old_process = old_process.pid
print old_process
        i = i+1;

It maybe happened that the a new process was kill the *second new* process
before the old process received the signal, any better solutions instead of
add sleep time here?


thanks,
Linhua Tan

Reply via email to