summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLeonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>2015-09-10 11:59:45 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-26 18:04:04 +0100
commit851e53a216682fc9133f51c05a24527cfc677741 (patch)
treeeb34a5627c1e6d1b5c57fc00e9eef4f94d6e05d2 /lib
parentc1b4754f69003df1a83fafc1c80a9ef74400b6dd (diff)
downloadbitbake-851e53a216682fc9133f51c05a24527cfc677741.zip
prserv/serv.py: Better messaging when starting/stopping the server with port=0
When starting the server using port=0, the server actually starts with a different port, so print a message with this new value. When stopping the server with port=0, advise the user which ports the server is listening to, so next time it tries to close it, user can pick up the correct one. [YOCTO #8560] Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/prserv/serv.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index c557837b..eafc3aab 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -306,9 +306,16 @@ def start_daemon(dbfile, host, port, logfile):
server = PRServer(os.path.abspath(dbfile), os.path.abspath(logfile), (ip,port))
server.start()
+ # Sometimes, the port (i.e. localhost:0) indicated by the user does not match with
+ # the one the server actually is listening, so at least warn the user about it
+ _,rport = server.getinfo()
+ if port != rport:
+ sys.stdout.write("Server is listening at port %s instead of %s\n"
+ % (rport,port))
return 0
def stop_daemon(host, port):
+ import glob
ip = socket.gethostbyname(host)
pidfile = PIDPREFIX % (ip, port)
try:
@@ -319,8 +326,20 @@ def stop_daemon(host, port):
pid = None
if not pid:
- sys.stderr.write("pidfile %s does not exist. Daemon not running?\n"
- % pidfile)
+ # when server starts at port=0 (i.e. localhost:0), server actually takes another port,
+ # so at least advise the user which ports the corresponding server is listening
+ ports = []
+ portstr = ""
+ for pf in glob.glob(PIDPREFIX % (ip,'*')):
+ bn = os.path.basename(pf)
+ root, _ = os.path.splitext(bn)
+ ports.append(root.split('_')[-1])
+ if len(ports):
+ portstr = "Wrong port? Other ports listening at %s: %s" % (host, ' '.join(ports))
+
+ sys.stderr.write("pidfile %s does not exist. Daemon not running? %s\n"
+ % (pidfile,portstr))
+ return 1
try:
PRServerConnection(ip, port).terminate()