* [PATCH v2 0/3] PRServer: Fixes daemon issues
@ 2015-09-24 8:52 leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 1/3] prserv/serv: Start/Stop daemon using ip instead of host leonardo.sandoval.gonzalez
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: leonardo.sandoval.gonzalez @ 2015-09-24 8:52 UTC (permalink / raw)
To: openembedded-core
From: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
First two patches fix issues when using hostnames instead of IPs. Third patch
disconnect the DB manually, not relaying on this task into a __del__ function.
Detail is given on each patch. Fixes 8258, 8560 and 8215
Changes from v1:
* First patch: No changes
* Second patch: outputs the message into stdout instead of stderr. Also
removes the 'WARNING' string.
* Third patch: Instead of changing the journal, this patch closes
the DB connection explicitly, instead of relying on the __del__
function
The following changes since commit 71b0568fa43285f0946fae93fb43cea5f3bbecec:
rt-tests: drop unnecessary added-missing-dependencies.patch (2015-09-01 11:44:04 +0100)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib lsandov1/prserver
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=lsandov1/prserver
Leonardo Sandoval (3):
prserv/serv: Start/Stop daemon using ip instead of host
prserv/serv.py: Better messaging when starting/stopping the server
with port=0
prserv/serv: Close the DB connection out of class destructor
bitbake/lib/prserv/db.py | 2 +-
bitbake/lib/prserv/serv.py | 38 ++++++++++++++++++++++++++++++--------
2 files changed, 31 insertions(+), 9 deletions(-)
--
1.8.4.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] prserv/serv: Start/Stop daemon using ip instead of host
2015-09-24 8:52 [PATCH v2 0/3] PRServer: Fixes daemon issues leonardo.sandoval.gonzalez
@ 2015-09-24 8:52 ` leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 2/3] prserv/serv.py: Better messaging when starting/stopping the server with port=0 leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 3/3] prserv/serv: Close the DB connection out of class destructor leonardo.sandoval.gonzalez
2 siblings, 0 replies; 4+ messages in thread
From: leonardo.sandoval.gonzalez @ 2015-09-24 8:52 UTC (permalink / raw)
To: openembedded-core
From: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
In cases where hostname is given instead of an IP (i.e. localhost
instead of 127.0.0.1) when stopping the server with bitbake-prserv --stop,
the server shows a misleading message indicating that the daemon was not
found, where it is actually stopped. This patch converts host to IP values
before starting/stopping the daemon, so it will always work on IP, not on
hostnames, avoiding problems like the latter.
[YOCTO #8258]
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
---
bitbake/lib/prserv/serv.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
index 0507485..0d96963 100644
--- a/bitbake/lib/prserv/serv.py
+++ b/bitbake/lib/prserv/serv.py
@@ -3,6 +3,7 @@ import signal, time
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
import threading
import Queue
+import socket
try:
import sqlite3
@@ -37,7 +38,6 @@ singleton = None
class PRServer(SimpleXMLRPCServer):
def __init__(self, dbfile, logfile, interface, daemon=True):
''' constructor '''
- import socket
try:
SimpleXMLRPCServer.__init__(self, interface,
logRequests=False, allow_none=True)
@@ -261,7 +261,8 @@ class PRServerConnection(object):
return self.host, self.port
def start_daemon(dbfile, host, port, logfile):
- pidfile = PIDPREFIX % (host, port)
+ ip = socket.gethostbyname(host)
+ pidfile = PIDPREFIX % (ip, port)
try:
pf = file(pidfile,'r')
pid = int(pf.readline().strip())
@@ -274,12 +275,14 @@ def start_daemon(dbfile, host, port, logfile):
% pidfile)
return 1
- server = PRServer(os.path.abspath(dbfile), os.path.abspath(logfile), (host,port))
+ server = PRServer(os.path.abspath(dbfile), os.path.abspath(logfile), (ip,port))
server.start()
+
return 0
def stop_daemon(host, port):
- pidfile = PIDPREFIX % (host, port)
+ ip = socket.gethostbyname(host)
+ pidfile = PIDPREFIX % (ip, port)
try:
pf = file(pidfile,'r')
pid = int(pf.readline().strip())
@@ -292,7 +295,7 @@ def stop_daemon(host, port):
% pidfile)
try:
- PRServerConnection(host, port).terminate()
+ PRServerConnection(ip, port).terminate()
except:
logger.critical("Stop PRService %s:%d failed" % (host,port))
--
1.8.4.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] prserv/serv.py: Better messaging when starting/stopping the server with port=0
2015-09-24 8:52 [PATCH v2 0/3] PRServer: Fixes daemon issues leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 1/3] prserv/serv: Start/Stop daemon using ip instead of host leonardo.sandoval.gonzalez
@ 2015-09-24 8:52 ` leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 3/3] prserv/serv: Close the DB connection out of class destructor leonardo.sandoval.gonzalez
2 siblings, 0 replies; 4+ messages in thread
From: leonardo.sandoval.gonzalez @ 2015-09-24 8:52 UTC (permalink / raw)
To: openembedded-core
From: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
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>
---
bitbake/lib/prserv/serv.py | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
index 0d96963..3558d4d 100644
--- a/bitbake/lib/prserv/serv.py
+++ b/bitbake/lib/prserv/serv.py
@@ -278,9 +278,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:
@@ -291,8 +298,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()
--
1.8.4.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] prserv/serv: Close the DB connection out of class destructor
2015-09-24 8:52 [PATCH v2 0/3] PRServer: Fixes daemon issues leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 1/3] prserv/serv: Start/Stop daemon using ip instead of host leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 2/3] prserv/serv.py: Better messaging when starting/stopping the server with port=0 leonardo.sandoval.gonzalez
@ 2015-09-24 8:52 ` leonardo.sandoval.gonzalez
2 siblings, 0 replies; 4+ messages in thread
From: leonardo.sandoval.gonzalez @ 2015-09-24 8:52 UTC (permalink / raw)
To: openembedded-core
From: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
When launching the PR server daemon, the PRData __del__ function was being
called (no reason found yet) where the DB connection closed, thus following
PR updates were not getting into the DB. This patch closes the connection
explicitly, not relaying on the __del__ function execution.
Closing the connection in turn causes all WAL file transactions to be moved
into the database (checkpoint), thus effectively updating the database.
[YOCTO #8215]
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
---
bitbake/lib/prserv/db.py | 2 +-
bitbake/lib/prserv/serv.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/bitbake/lib/prserv/db.py b/bitbake/lib/prserv/db.py
index 4379580..36c9f7b 100644
--- a/bitbake/lib/prserv/db.py
+++ b/bitbake/lib/prserv/db.py
@@ -248,7 +248,7 @@ class PRData(object):
self.connection.execute("PRAGMA journal_mode = WAL;")
self._tables={}
- def __del__(self):
+ def disconnect(self):
self.connection.close()
def __getitem__(self,tblname):
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
index 3558d4d..08298a6 100644
--- a/bitbake/lib/prserv/serv.py
+++ b/bitbake/lib/prserv/serv.py
@@ -141,7 +141,7 @@ class PRServer(SimpleXMLRPCServer):
while not self.quit:
self.handle_request()
self.handlerthread.join()
- self.table.sync()
+ self.db.disconnect()
logger.info("PRServer: stopping...")
self.server_close()
return
--
1.8.4.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-24 17:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-24 8:52 [PATCH v2 0/3] PRServer: Fixes daemon issues leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 1/3] prserv/serv: Start/Stop daemon using ip instead of host leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 2/3] prserv/serv.py: Better messaging when starting/stopping the server with port=0 leonardo.sandoval.gonzalez
2015-09-24 8:52 ` [PATCH v2 3/3] prserv/serv: Close the DB connection out of class destructor leonardo.sandoval.gonzalez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox