Commit e6d8a8ca authored by Gabriel Monnerat's avatar Gabriel Monnerat

add function to stop a paster process that is listening on port. The goal of...

add function to stop a paster process that is listening on port. The goal of this function is clean the processes who are breaking the buildbot

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@45210 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6e1b42d6
......@@ -8,12 +8,13 @@ from subprocess import Popen
from ConfigParser import ConfigParser
from argparse import ArgumentParser
from os import chdir, path, environ, curdir, remove
from psutil import Process
import psutil
from cloudooo.handler.ooo.utils.utils import socketStatus
from signal import SIGQUIT
def wait_use_port(pid, timeout_limit=30):
process = Process(pid)
process = psutil.Process(pid)
for n in range(timeout_limit):
if len(process.get_connections()) > 0:
return True
......@@ -21,6 +22,22 @@ def wait_use_port(pid, timeout_limit=30):
return False
def stopDaemonProcess(port):
"""
Temporary Function to stop the paster daemon. The goals is to stop the
server that is running forever using the port.
"""
for process in psutil.process_iter():
if process.name == "paster" and "paster serve" in " ".join(process.cmdline):
try:
connection_list = process.get_connections()
for connection in connection_list:
if connection.status == "LISTEN" and connection.local_address[1] == port:
process.send_signal(SIGQUIT)
except psutil.error.AccessDenied, e:
pass
def exit(msg):
sys.stderr.write(msg)
sys.exit(0)
......@@ -77,6 +94,10 @@ def run(handler_name):
if DAEMON:
log_file = '%s/cloudooo_test.log' % config.get('app:main',
'working_path')
hostname = config.get("server:main", "host")
port = int(config.get("server:main", "port"))
if socketStatus(hostname, port):
stopDaemonProcess(port)
if path.exists(log_file):
remove(log_file)
command = [paster_path, 'serve', '--log-file', log_file,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment