def __init__( self, reposDir, sslCertAndKey=None, withCache=True, singleWorker=False, configValues=(), ): self.reposDir = os.path.abspath(reposDir) self.reposLog = os.path.join(self.reposDir, 'repos.log') self.traceLog = os.path.join(self.reposDir, 'trace.log') self.configPath = os.path.join(self.reposDir, 'repository.cnr') self.contents = ContentStore(os.path.join(self.reposDir, 'contents')) if withCache: self.cache = ContentStore(os.path.join(self.reposDir, 'cscache')) self.cache.reset() self.sslCertAndKey = sslCertAndKey if sslCertAndKey is True: self.sslCertAndKey = (resources.get_archive('ssl-cert.crt'), resources.get_archive('ssl-cert.key')) name = os.environ.get('CONARY_APP_SERVER', 'gunicorn') appServerClass = self.appServerClasses[name] self.appServer = appServerClass( serverDir=os.path.join(self.reposDir, 'appserver'), workers=(1 if singleWorker else 2), application='conary.server.wsgi_hooks', environ={ 'CONARY_SERVER_CONFIG': self.configPath, }, ) self.rpServer = NginxServer( serverDir=os.path.join(self.reposDir, 'revproxy'), proxyTo=self.appServer.getProxyTo(), sslCertAndKey=self.sslCertAndKey, ) self.configValues = configValues self.needsReset = True
def __init__(self, reposDir, sslCertAndKey=None, withCache=True, singleWorker=False, configValues=(), ): self.reposDir = os.path.abspath(reposDir) self.reposLog = os.path.join(self.reposDir, 'repos.log') self.traceLog = os.path.join(self.reposDir, 'trace.log') self.configPath = os.path.join(self.reposDir, 'repository.cnr') self.contents = ContentStore(os.path.join(self.reposDir, 'contents')) if withCache: self.cache = ContentStore(os.path.join(self.reposDir, 'cscache')) self.cache.reset() self.sslCertAndKey = sslCertAndKey if sslCertAndKey is True: self.sslCertAndKey = ( resources.get_archive('ssl-cert.crt'), resources.get_archive('ssl-cert.key')) name = os.environ.get('CONARY_APP_SERVER', 'gunicorn') appServerClass = self.appServerClasses[name] self.appServer = appServerClass( serverDir=os.path.join(self.reposDir, 'appserver'), workers=(1 if singleWorker else 2), application='conary.server.wsgi_hooks', environ={ 'CONARY_SERVER_CONFIG': self.configPath, }, ) self.rpServer = NginxServer( serverDir=os.path.join(self.reposDir, 'revproxy'), proxyTo=self.appServer.getProxyTo(), sslCertAndKey=self.sslCertAndKey, ) self.configValues = configValues self.needsReset = True
class ConaryServer(object): cache = None reposDB = None appServerClasses = { 'gunicorn': GunicornServer, 'uwsgi': UwsgiServer, } def __init__(self, reposDir, sslCertAndKey=None, withCache=True, singleWorker=False, configValues=(), ): self.reposDir = os.path.abspath(reposDir) self.reposLog = os.path.join(self.reposDir, 'repos.log') self.traceLog = os.path.join(self.reposDir, 'trace.log') self.configPath = os.path.join(self.reposDir, 'repository.cnr') self.contents = ContentStore(os.path.join(self.reposDir, 'contents')) if withCache: self.cache = ContentStore(os.path.join(self.reposDir, 'cscache')) self.cache.reset() self.sslCertAndKey = sslCertAndKey if sslCertAndKey is True: self.sslCertAndKey = ( resources.get_archive('ssl-cert.crt'), resources.get_archive('ssl-cert.key')) name = os.environ.get('CONARY_APP_SERVER', 'gunicorn') appServerClass = self.appServerClasses[name] self.appServer = appServerClass( serverDir=os.path.join(self.reposDir, 'appserver'), workers=(1 if singleWorker else 2), application='conary.server.wsgi_hooks', environ={ 'CONARY_SERVER_CONFIG': self.configPath, }, ) self.rpServer = NginxServer( serverDir=os.path.join(self.reposDir, 'revproxy'), proxyTo=self.appServer.getProxyTo(), sslCertAndKey=self.sslCertAndKey, ) self.configValues = configValues self.needsReset = True def reset(self): self.checkForTracebacks() for thing in ( self.appServer, self.rpServer, self.contents, self.reposDB, self.cache, ): if thing: thing.reset() self.needsReset = False def resetIfNeeded(self): if self.needsReset: self.reset() def setNeedsReset(self): self.needsReset = True def start(self): self.needsReset = True self.createConfig() self.appServer.start() self.rpServer.start() def stop(self): self.checkForTracebacks() self.rpServer.stop() self.appServer.stop() def checkForTracebacks(self): try: with open(self.appServer.errorLog) as f: data = f.read() if 'Traceback (most recent call last)' in data: print >> sys.stderr, "Contents of error.log after test:" print >> sys.stderr, data sys.stderr.flush() except IOError, err: if err.args[0] != errno.ENOENT: raise
class ConaryServer(object): cache = None reposDB = None appServerClasses = { 'gunicorn': GunicornServer, 'uwsgi': UwsgiServer, } def __init__( self, reposDir, sslCertAndKey=None, withCache=True, singleWorker=False, configValues=(), ): self.reposDir = os.path.abspath(reposDir) self.reposLog = os.path.join(self.reposDir, 'repos.log') self.traceLog = os.path.join(self.reposDir, 'trace.log') self.configPath = os.path.join(self.reposDir, 'repository.cnr') self.contents = ContentStore(os.path.join(self.reposDir, 'contents')) if withCache: self.cache = ContentStore(os.path.join(self.reposDir, 'cscache')) self.cache.reset() self.sslCertAndKey = sslCertAndKey if sslCertAndKey is True: self.sslCertAndKey = (resources.get_archive('ssl-cert.crt'), resources.get_archive('ssl-cert.key')) name = os.environ.get('CONARY_APP_SERVER', 'gunicorn') appServerClass = self.appServerClasses[name] self.appServer = appServerClass( serverDir=os.path.join(self.reposDir, 'appserver'), workers=(1 if singleWorker else 2), application='conary.server.wsgi_hooks', environ={ 'CONARY_SERVER_CONFIG': self.configPath, }, ) self.rpServer = NginxServer( serverDir=os.path.join(self.reposDir, 'revproxy'), proxyTo=self.appServer.getProxyTo(), sslCertAndKey=self.sslCertAndKey, ) self.configValues = configValues self.needsReset = True def reset(self): self.checkForTracebacks() for thing in ( self.appServer, self.rpServer, self.contents, self.reposDB, self.cache, ): if thing: thing.reset() self.needsReset = False def resetIfNeeded(self): if self.needsReset: self.reset() def setNeedsReset(self): self.needsReset = True def start(self): self.needsReset = True self.createConfig() self.appServer.start() self.rpServer.start() def stop(self): self.checkForTracebacks() self.rpServer.stop() self.appServer.stop() def checkForTracebacks(self): try: with open(self.appServer.errorLog) as f: data = f.read() if 'Traceback (most recent call last)' in data: print >> sys.stderr, "Contents of error.log after test:" print >> sys.stderr, data sys.stderr.flush() except IOError, err: if err.args[0] != errno.ENOENT: raise