mirror of https://github.com/apache/lucene.git
don't hang if Solr example fails to start
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1407083 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1897641123
commit
c85875c33e
|
@ -463,17 +463,13 @@ def cygwinifyPaths(command):
|
||||||
if '; ant ' in command: command = reUnixPath.sub(unix2win, command)
|
if '; ant ' in command: command = reUnixPath.sub(unix2win, command)
|
||||||
return command
|
return command
|
||||||
|
|
||||||
def run(command, logFile):
|
def printFileContents(fileName):
|
||||||
if cygwin: command = cygwinifyPaths(command)
|
|
||||||
if os.system('%s > %s 2>&1' % (command, logFile)):
|
|
||||||
logPath = os.path.abspath(logFile)
|
|
||||||
print('\ncommand "%s" failed:' % command)
|
|
||||||
|
|
||||||
# Assume log file was written in system's default encoding, but
|
# Assume log file was written in system's default encoding, but
|
||||||
# even if we are wrong, we replace errors ... the ASCII chars
|
# even if we are wrong, we replace errors ... the ASCII chars
|
||||||
# (which is what we mostly care about eg for the test seed) should
|
# (which is what we mostly care about eg for the test seed) should
|
||||||
# still survive:
|
# still survive:
|
||||||
txt = codecs.open(logPath, 'r', encoding=sys.getdefaultencoding(), errors='replace').read()
|
txt = codecs.open(fileName, 'r', encoding=sys.getdefaultencoding(), errors='replace').read()
|
||||||
|
|
||||||
# Encode to our output encoding (likely also system's default
|
# Encode to our output encoding (likely also system's default
|
||||||
# encoding):
|
# encoding):
|
||||||
|
@ -484,6 +480,12 @@ def run(command, logFile):
|
||||||
print(codecs.getdecoder(sys.stdout.encoding)(bytes)[0])
|
print(codecs.getdecoder(sys.stdout.encoding)(bytes)[0])
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
def run(command, logFile):
|
||||||
|
if cygwin: command = cygwinifyPaths(command)
|
||||||
|
if os.system('%s > %s 2>&1' % (command, logFile)):
|
||||||
|
logPath = os.path.abspath(logFile)
|
||||||
|
print('\ncommand "%s" failed:' % command)
|
||||||
|
printFileContents(logFile)
|
||||||
raise RuntimeError('command "%s" failed; see log file %s' % (command, logPath))
|
raise RuntimeError('command "%s" failed; see log file %s' % (command, logPath))
|
||||||
|
|
||||||
def verifyDigests(artifact, urlString, tmpDir):
|
def verifyDigests(artifact, urlString, tmpDir):
|
||||||
|
@ -762,19 +764,29 @@ def readSolrOutput(p, startupEvent, failureEvent, logFile):
|
||||||
f = open(logFile, 'wb')
|
f = open(logFile, 'wb')
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
line = p.readline()
|
line = p.stderr.readline()
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
|
p.poll()
|
||||||
|
if not startupEvent.isSet():
|
||||||
|
failureEvent.set()
|
||||||
|
startupEvent.set()
|
||||||
break
|
break
|
||||||
f.write(line)
|
f.write(line)
|
||||||
f.flush()
|
f.flush()
|
||||||
# print 'SOLR: %s' % line.strip()
|
#print('SOLR: %s' % line.strip())
|
||||||
if not startupEvent.isSet() and line.find(b'Started SocketConnector@0.0.0.0:8983') != -1:
|
if not startupEvent.isSet():
|
||||||
|
if line.find(b'Started SocketConnector@0.0.0.0:8983') != -1:
|
||||||
startupEvent.set()
|
startupEvent.set()
|
||||||
|
elif p.poll() is not None:
|
||||||
|
failureEvent.set()
|
||||||
|
startupEvent.set()
|
||||||
|
break
|
||||||
except:
|
except:
|
||||||
print()
|
print()
|
||||||
print('Exception reading Solr output:')
|
print('Exception reading Solr output:')
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
failureEvent.set()
|
failureEvent.set()
|
||||||
|
startupEvent.set()
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
@ -786,16 +798,24 @@ def testSolrExample(unpackPath, javaPath, isSrc):
|
||||||
env.update(os.environ)
|
env.update(os.environ)
|
||||||
env['JAVA_HOME'] = javaPath
|
env['JAVA_HOME'] = javaPath
|
||||||
env['PATH'] = '%s/bin:%s' % (javaPath, env['PATH'])
|
env['PATH'] = '%s/bin:%s' % (javaPath, env['PATH'])
|
||||||
server = subprocess.Popen(['java', '-jar', 'start.jar'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
|
server = subprocess.Popen(['java', '-jar', 'start.jar'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, env=env)
|
||||||
|
|
||||||
startupEvent = threading.Event()
|
startupEvent = threading.Event()
|
||||||
failureEvent = threading.Event()
|
failureEvent = threading.Event()
|
||||||
serverThread = threading.Thread(target=readSolrOutput, args=(server.stderr, startupEvent, failureEvent, logFile))
|
serverThread = threading.Thread(target=readSolrOutput, args=(server, startupEvent, failureEvent, logFile))
|
||||||
serverThread.setDaemon(True)
|
serverThread.setDaemon(True)
|
||||||
serverThread.start()
|
serverThread.start()
|
||||||
|
|
||||||
# Make sure Solr finishes startup:
|
# Make sure Solr finishes startup:
|
||||||
startupEvent.wait()
|
if not startupEvent.wait(1800):
|
||||||
|
raise RuntimeError('startup took more than 30 minutes')
|
||||||
|
if failureEvent.isSet():
|
||||||
|
logFile = os.path.abspath(logFile)
|
||||||
|
print
|
||||||
|
print('Startup failed; see log %s' % logFile)
|
||||||
|
printFileContents(logFile)
|
||||||
|
raise RuntimeError('failure on startup; see log %s' % logFile)
|
||||||
|
|
||||||
print(' startup done')
|
print(' startup done')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue