def remote_transaction_mysql(conn_info): MYSQL_FORWARDED_PORT = 33000 utils.kill_listening_processes(MYSQL_FORWARDED_PORT) if utils.can_connect(MYSQL_FORWARDED_PORT): raise Exception('MySQL tunnel port (%s) is not ' 'available' % MYSQL_FORWARDED_PORT) ssh_command_line = utils.ssh_command_line( self.config, extra_opts='-N -L {forwarded_port}:localhost:3306'.format( forwarded_port=MYSQL_FORWARDED_PORT)) log.debug('ssh command line for tunnel: %s', ssh_command_line) p = subprocess.Popen(ssh_command_line, shell=True) log.info('Waiting a bit for the tunnel to establish...') time.sleep(3) remote_conn_info = db_backends.ConnectionInfo( self.config.remote_conn_string) remote_conn_info.data['port'] = MYSQL_FORWARDED_PORT remote_conn_info.data['host'] = '127.0.0.1' yield remote_conn_info p.kill()
def kill_existing(cls, env, kill_proxy=True): ports_to_check = [env.c.port] if kill_proxy and env.c.wsgi_proxy: ports_to_check.append(env.c.wsgi_proxy_port) for port in ports_to_check: utils.kill_listening_processes(port) if utils.can_connect(port): raise DaemonException( 'Error, something is already listening on port %s' % port)
def _wait_until_ready(self): # TODO: make it an option? WAIT_TIME_S = 10 * 60 POLL_INTERVAL_S = 2 for i in range(WAIT_TIME_S / POLL_INTERVAL_S): if not self.is_running(): raise DaemonException( 'Server has exited prematurely. Check the logs for details.') if utils.can_connect(self.env.c.port, True): break time.sleep(POLL_INTERVAL_S) else: raise DaemonException('Server is not responding')
def _wait_until_ready(self): # TODO: make it an option? WAIT_TIME_S = 10 * 60 POLL_INTERVAL_S = 2 for i in range(WAIT_TIME_S / POLL_INTERVAL_S): if not self.is_running(): raise DaemonException( 'Server has exited prematurely. Check the logs for details.' ) if utils.can_connect(self.env.c.port, True): break time.sleep(POLL_INTERVAL_S) else: raise DaemonException('Server is not responding')
def serve_forever(env, project): utils.kill_listening_processes(env.c.wsgi_proxy_port) if utils.can_connect(env.c.wsgi_proxy_port): raise Exception("Error, something is already listening on port %s", env.c.wsgi_proxy_port) proxy = start(env, project) log.info("Proxy running, press ctrl-c to stop") try: while True: time.sleep(10) except KeyboardInterrupt: print "^C" log.info("Stopping proxy") stop()
def serve_forever(env, project): utils.kill_listening_processes(env.c.wsgi_proxy_port) if utils.can_connect(env.c.wsgi_proxy_port): raise Exception('Error, something is already listening on port %s', env.c.wsgi_proxy_port) proxy = start(env, project) log.info('Proxy running, press ctrl-c to stop') try: while True: time.sleep(10) except KeyboardInterrupt: print '^C' log.info('Stopping proxy') stop()
def hang_detector(): HANG_CHECK_INTERVAL_S = 60 RESTART_HANG_COUNT = 2 hangs_count = 0 while hang_detector_running: if not self.daemon.ready: log.debug('Hang detector: daemon not ready') time.sleep(HANG_CHECK_INTERVAL_S) hangs_count = 0 continue log.debug('Checking for hangs') if not utils.can_connect(self.config.port, False, '/hang_check'): hangs_count += 1 log.warn('Detected hang. Hangs count is %s', hangs_count) else: hangs_count = 0 if hangs_count >= RESTART_HANG_COUNT: hangs_count = 0 log.warn('Hang detected, setting hang detected event.') hang_detected_event.set() time.sleep(HANG_CHECK_INTERVAL_S)
pid = int(open(pid_path).read()) log.info('daemon ready on port %i %s (script pid: %i)', self.env.c.port, '' if pid < 0 else 'with pid %i' % pid, os.getpid()) self._ready = True try: self._start_wsgi_proxy() except socket.error, e: # XXX Ignore address already in use if restarted. if kill_proxy: raise log.warn('Ignoring address already in use for wsgi proxy') def stop(self): # TODO: should use quit action, but it doesn't work (at least on Windows) # http://localhost:9080/synthese3/admin?a=QuitAction&co=0&sid=FKlwsUfU4lLCId38cCBI try: if not self.proc: return try: self.proc.terminate() except Exception, e: log.debug('Ignoring exception when calling terminate: %r', e) time.sleep(2) self.proc = None finally: self._clean_pid_file() self._stop_wsgi_proxy() assert not utils.can_connect(self.env.c.port, False) self.stopped = True self._ready = False
log.info('daemon ready on port %i %s (script pid: %i)', self.env.c.port, '' if pid < 0 else 'with pid %i' % pid, os.getpid()) self._ready = True try: self._start_wsgi_proxy() except socket.error, e: # XXX Ignore address already in use if restarted. if kill_proxy: raise log.warn('Ignoring address already in use for wsgi proxy') def stop(self): # TODO: should use quit action, but it doesn't work (at least on Windows) # http://localhost:9080/synthese3/admin?a=QuitAction&co=0&sid=FKlwsUfU4lLCId38cCBI try: if not self.proc: return try: self.proc.terminate() except Exception, e: log.debug('Ignoring exception when calling terminate: %r', e) time.sleep(2) self.proc = None finally: self._clean_pid_file() self._stop_wsgi_proxy() assert not utils.can_connect(self.env.c.port, False) self.stopped = True self._ready = False