diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-02-06 23:18:19 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-02-06 23:45:27 +0000 |
commit | bb53b47710ca4579e20284668cb354f734c3d502 (patch) | |
tree | 0c1f518f6105bce7f033b4f0ab0e813459b0f44c /lib/prserv/serv.py | |
parent | 2d0bbd9398ab839bd2d1e29e50b25d52efb1ce2a (diff) | |
download | bitbake-bb53b47710ca4579e20284668cb354f734c3d502.tar.gz |
prserv/serv.py: Fix logging in daemon mode
In deamon mode we need to ensure the logging module is sending log data to the
log file. These changes ensure this happens correctly.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/prserv/serv.py')
-rw-r--r-- | lib/prserv/serv.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py index 719941b32..348920053 100644 --- a/lib/prserv/serv.py +++ b/lib/prserv/serv.py @@ -86,7 +86,8 @@ class PRServer(SimpleXMLRPCServer): def work_forever(self,): self.quit = False self.timeout = 0.5 - logger.info("PRServer: started! DBfile: %s, IP: %s, PORT: %s, PID: %s" % + + logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" % (self.dbfile, self.host, self.port, str(os.getpid()))) while not self.quit: @@ -97,7 +98,10 @@ class PRServer(SimpleXMLRPCServer): return def start(self): - self.daemonize() + pid = self.daemonize() + # Ensure both the parent sees this and the child from the work_forever log entry above + logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" % + (self.dbfile, self.host, self.port, str(pid))) def delpid(self): os.remove(self.pidfile) @@ -111,7 +115,7 @@ class PRServer(SimpleXMLRPCServer): if pid > 0: os.waitpid(pid, 0) #parent return instead of exit to give control - return + return pid except OSError as e: raise Exception("%s [%d]" % (e.strerror, e.errno)) @@ -139,14 +143,21 @@ class PRServer(SimpleXMLRPCServer): os.dup2(so.fileno(),sys.stdout.fileno()) os.dup2(se.fileno(),sys.stderr.fileno()) + # Ensure logging makes it to the logfile + streamhandler = logging.StreamHandler() + streamhandler.setLevel(logging.DEBUG) + formatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") + streamhandler.setFormatter(formatter) + logger.addHandler(streamhandler) + # write pidfile - atexit.register(self.delpid) pid = str(os.getpid()) pf = file(self.pidfile, 'w') pf.write("%s\n" % pid) pf.close() self.work_forever() + self.delpid os._exit(0) class PRServSingleton(): @@ -179,6 +190,7 @@ class PRServerConnection(): import socket socket.setdefaulttimeout(2) try: + logger.info("Terminating PRServer...") self.connection.quit() except Exception as exc: sys.stderr.write("%s\n" % str(exc)) |