Permalink
Browse files

updated for changed format of ports.json; fixed handling of errors at…

… service startup; logs now auto-flush
  • Loading branch information...
1 parent a3a0f84 commit 9faa346039f48c148fcc52d0ec7db524e3bdd7cf @trey0 trey0 committed Oct 19, 2012
Showing with 26 additions and 17 deletions.
  1. +7 −0 geocamPycroraptor2/log.py
  2. +1 −1 geocamPycroraptor2/manager.py
  3. +18 −16 geocamPycroraptor2/service.py
@@ -90,6 +90,13 @@ def openLogFromTemplate(owner, fnameTemplate, env):
return (fname, openLogFromPath(owner, fname))
+class AutoFlushStreamHandler(logging.StreamHandler):
+ def emit(self, rec):
+ result = super(AutoFlushStreamHandler, self).emit(rec)
+ self.flush()
+ return result
+
+
class LineBuffer(logging.Handler):
def __init__(self, maxSize=2048):
self._maxSize = maxSize
@@ -78,7 +78,7 @@ def _start(self):
# load ports config
self._ports = loadConfig(self._config.PORTS)
- self._port = self._ports[self._name]
+ self._port = self._ports.zerorpc[self._name]
if not self._opts.foreground:
self._logger.debug('daemonizing')
@@ -80,7 +80,8 @@ def start(self):
logPath,
self._env))
- sh = logging.StreamHandler(self._log)
+ #sh = logging.StreamHandler(self._log)
+ sh = log.AutoFlushStreamHandler(self._log)
sh.setLevel(logging.DEBUG)
sh.setFormatter(log.UtcFormatter('%(asctime)s %(name)s %(message)s'))
self._logger.addHandler(sh)
@@ -92,17 +93,6 @@ def start(self):
self._eventLogger = self._logger.getChild('evt n')
self._eventLogger.setLevel(logging.DEBUG)
- self._stdinLogger = self._logger.getChild('inp')
- self._stdinLogger.setLevel(logging.DEBUG)
-
- self._outLogger = (log.StreamLogger
- (childStdoutReadFd,
- self._logger.getChild('out')))
-
- self._errLogger = (log.StreamLogger
- (childStderrReadFd,
- self._logger.getChild('err')))
-
workingDir = self.getWorkingDir()
if workingDir:
os.chdir(workingDir)
@@ -120,6 +110,7 @@ def start(self):
for arg in cmdArgs])
self._eventLogger.info('command: %s', escapedArgs)
+ startupError = None
try:
self._proc = subprocess.Popen(cmdArgs,
stdin=subprocess.PIPE,
@@ -131,20 +122,31 @@ def start(self):
if oe.errno == errno.ENOENT:
startupError = ('is executable "%s" in PATH? Popen call returned no such file or directory'
% cmdArgs[0])
+ else:
+ startupError = oe
except Exception, exc:
startupError = exc
- else:
- startupError = None
trackerG.close(childStdoutWriteFd)
trackerG.close(childStderrWriteFd)
- if startupError:
- self._eventLogger.log(['startupError', startupError])
+ if startupError is not None:
+ self._eventLogger.warning('startup error: %s', startupError)
+ self._parent._logger.debug('failed to start service %s', self._name)
self._setStatus(dict(status=statuslib.FAILED,
procStatus=statuslib.ERROR_EXIT,
returnValue=1,
startupFailed=1))
self._postExitCleanup()
else:
+ self._stdinLogger = self._logger.getChild('inp')
+ self._stdinLogger.setLevel(logging.DEBUG)
+
+ self._outLogger = (log.StreamLogger
+ (childStdoutReadFd,
+ self._logger.getChild('out')))
+
+ self._errLogger = (log.StreamLogger
+ (childStderrReadFd,
+ self._logger.getChild('err')))
self._childStdin = self._proc.stdin
self._setStatus(dict(status=statuslib.RUNNING,
procStatus=statuslib.RUNNING,

0 comments on commit 9faa346

Please sign in to comment.