summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-02-06 23:18:19 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-02-06 23:45:36 +0000
commit1ef926cf788359b9845394bf95e298b7fcff4910 (patch)
treeebc490e516bd523b73485acc1815b7c4ca93cdb2
parentbdfc5207a0fdbed889c4a5997306adab82b1c2d4 (diff)
downloadpoky-1ef926cf788359b9845394bf95e298b7fcff4910.tar.gz
bitbake: 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. (Bitbake rev: bb53b47710ca4579e20284668cb354f734c3d502) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/prserv/serv.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
index 719941b32e..3489200536 100644
--- a/bitbake/lib/prserv/serv.py
+++ b/bitbake/lib/prserv/serv.py
@@ -86,7 +86,8 @@ class PRServer(SimpleXMLRPCServer):
86 def work_forever(self,): 86 def work_forever(self,):
87 self.quit = False 87 self.quit = False
88 self.timeout = 0.5 88 self.timeout = 0.5
89 logger.info("PRServer: started! DBfile: %s, IP: %s, PORT: %s, PID: %s" % 89
90 logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
90 (self.dbfile, self.host, self.port, str(os.getpid()))) 91 (self.dbfile, self.host, self.port, str(os.getpid())))
91 92
92 while not self.quit: 93 while not self.quit:
@@ -97,7 +98,10 @@ class PRServer(SimpleXMLRPCServer):
97 return 98 return
98 99
99 def start(self): 100 def start(self):
100 self.daemonize() 101 pid = self.daemonize()
102 # Ensure both the parent sees this and the child from the work_forever log entry above
103 logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
104 (self.dbfile, self.host, self.port, str(pid)))
101 105
102 def delpid(self): 106 def delpid(self):
103 os.remove(self.pidfile) 107 os.remove(self.pidfile)
@@ -111,7 +115,7 @@ class PRServer(SimpleXMLRPCServer):
111 if pid > 0: 115 if pid > 0:
112 os.waitpid(pid, 0) 116 os.waitpid(pid, 0)
113 #parent return instead of exit to give control 117 #parent return instead of exit to give control
114 return 118 return pid
115 except OSError as e: 119 except OSError as e:
116 raise Exception("%s [%d]" % (e.strerror, e.errno)) 120 raise Exception("%s [%d]" % (e.strerror, e.errno))
117 121
@@ -139,14 +143,21 @@ class PRServer(SimpleXMLRPCServer):
139 os.dup2(so.fileno(),sys.stdout.fileno()) 143 os.dup2(so.fileno(),sys.stdout.fileno())
140 os.dup2(se.fileno(),sys.stderr.fileno()) 144 os.dup2(se.fileno(),sys.stderr.fileno())
141 145
146 # Ensure logging makes it to the logfile
147 streamhandler = logging.StreamHandler()
148 streamhandler.setLevel(logging.DEBUG)
149 formatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
150 streamhandler.setFormatter(formatter)
151 logger.addHandler(streamhandler)
152
142 # write pidfile 153 # write pidfile
143 atexit.register(self.delpid)
144 pid = str(os.getpid()) 154 pid = str(os.getpid())
145 pf = file(self.pidfile, 'w') 155 pf = file(self.pidfile, 'w')
146 pf.write("%s\n" % pid) 156 pf.write("%s\n" % pid)
147 pf.close() 157 pf.close()
148 158
149 self.work_forever() 159 self.work_forever()
160 self.delpid
150 os._exit(0) 161 os._exit(0)
151 162
152class PRServSingleton(): 163class PRServSingleton():
@@ -179,6 +190,7 @@ class PRServerConnection():
179 import socket 190 import socket
180 socket.setdefaulttimeout(2) 191 socket.setdefaulttimeout(2)
181 try: 192 try:
193 logger.info("Terminating PRServer...")
182 self.connection.quit() 194 self.connection.quit()
183 except Exception as exc: 195 except Exception as exc:
184 sys.stderr.write("%s\n" % str(exc)) 196 sys.stderr.write("%s\n" % str(exc))