def on_close(self): logging.debug( 'connection closed for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id }) if MjpgClient.clients.pop(self._camera_id, None): logging.debug( 'mjpg client for camera %(camera_id)s on port %(port)s removed' % { 'port': self._port, 'camera_id': self._camera_id }) if getattr(self, 'error', None) and self.error.errno != errno.ECONNREFUSED: now = time.time() if now - MjpgClient._last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT: msg = 'connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id } logging.error(msg) if settings.MOTION_RESTART_ON_ERRORS: motionctl.stop(invalidate=True ) # this will close all the mjpg clients motionctl.start(deferred=True) MjpgClient._last_erroneous_close_time = now
def _garbage_collector(): io_loop = IOLoop.instance() io_loop.add_timeout( datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector) now = time.time() for camera_id, client in MjpgClient.clients.items(): port = client.get_port() if client.closed(): continue # check for jpeg frame timeout last_jpg_time = client.get_last_jpg_time() delta = now - last_jpg_time if delta > settings.MJPG_CLIENT_TIMEOUT: logging.error( 'mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s' % { 'camera_id': camera_id, 'port': port }) if settings.MOTION_RESTART_ON_ERRORS: motionctl.stop( invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) break # check for last access timeout '''
def _garbage_collector(): logging.debug('running garbage collector for mjpg clients...') now = datetime.datetime.utcnow() for client in MjpgClient.clients.values(): camera_id = client._camera_id port = client._port # check for last jpg moment timeout last_jpg_moment = MjpgClient.last_jpg_moment.get(camera_id) if last_jpg_moment is None: MjpgClient.last_jpg_moment[camera_id] = now continue if client.closed(): continue delta = now - last_jpg_moment delta = delta.days * 86400 + delta.seconds if delta > settings.MJPG_CLIENT_TIMEOUT: logging.error( 'mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s' % { 'camera_id': camera_id, 'port': port }) motionctl.stop( invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) break # check for last access timeout last_access = MjpgClient.last_access.get(camera_id) if last_access is None: continue delta = now - last_access delta = delta.days * 86400 + delta.seconds if settings.MJPG_CLIENT_IDLE_TIMEOUT and delta > settings.MJPG_CLIENT_IDLE_TIMEOUT: logging.debug( 'mjpg client for camera %(camera_id)s on port %(port)s has been idle for %(timeout)s seconds, removing it' % { 'camera_id': camera_id, 'port': port, 'timeout': settings.MJPG_CLIENT_IDLE_TIMEOUT }) client.close() continue io_loop = ioloop.IOLoop.instance() io_loop.add_timeout( datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector)
def _run_server(): import cleanup import motionctl import thumbnailer import tornado.ioloop import server server.application.listen(settings.PORT, settings.LISTEN) logging.info("server started") tornado.ioloop.IOLoop.instance().start() logging.info("server stopped") if thumbnailer.running(): thumbnailer.stop() logging.info("thumbnailer stopped") if cleanup.running(): cleanup.stop() logging.info("cleanup stopped") if motionctl.running(): motionctl.stop() logging.info("motion stopped") if settings.SMB_SHARES: smbctl.umount_all() logging.info("SMB shares unmounted")
def on_close(self): logging.debug( "connection closed for mjpg client for camera %(camera_id)s on port %(port)s" % {"port": self._port, "camera_id": self._camera_id} ) if MjpgClient.clients.pop(self._camera_id, None): MjpgClient.last_access.pop(self._camera_id, None) MjpgClient.last_jpg_moment.pop(self._camera_id, None) logging.debug( "mjpg client for camera %(camera_id)s on port %(port)s removed" % {"port": self._port, "camera_id": self._camera_id} ) if getattr(self, "error", None) and self.error.errno != errno.ECONNREFUSED: now = time.time() if now - MjpgClient.last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT: logging.error( "connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s" % {"port": self._port, "camera_id": self._camera_id} ) motionctl.stop(invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) MjpgClient.last_erroneous_close_time = now # remove the cached picture MjpgClient.last_jpgs.pop(self._camera_id, None)
def run(): import cleanup import motionctl import motioneye import smbctl import thumbnailer import tornado.ioloop configure_signals() logging.info('hello! this is motionEye server %s' % motioneye.VERSION) test_requirements() if settings.SMB_SHARES: stop, start = smbctl.update_mounts() # @UnusedVariable if start: start_motion() else: start_motion() start_cleanup() start_wsswitch() if settings.THUMBNAILER_INTERVAL: start_thumbnailer() template.add_context('static_path', settings.BASE_PATH + '/static/') application = Application(handler_mapping, debug=False, log_function=_log_request, static_path=settings.STATIC_PATH, static_url_prefix='/static/') application.listen(settings.PORT, settings.LISTEN) logging.info('server started') tornado.ioloop.IOLoop.instance().start() logging.info('server stopped') if thumbnailer.running(): thumbnailer.stop() logging.info('thumbnailer stopped') if cleanup.running(): cleanup.stop() logging.info('cleanup stopped') if motionctl.running(): motionctl.stop() logging.info('motion stopped') if settings.SMB_SHARES: smbctl.umount_all() logging.info('SMB shares unmounted') logging.info('bye!')
def _garbage_collector(): logging.debug('running garbage collector for mjpg clients...') io_loop = IOLoop.instance() io_loop.add_timeout( datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector) now = time.time() for camera_id, client in MjpgClient.clients.items(): port = client._port # check for jpeg frame timeout if not client._last_jpg_times: client._last_jpg_times.append(now) last_jpg_time = client._last_jpg_times[-1] if client.closed(): continue delta = now - last_jpg_time if delta > settings.MJPG_CLIENT_TIMEOUT: logging.error( 'mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s' % { 'camera_id': camera_id, 'port': port }) if settings.MOTION_RESTART_ON_ERRORS: motionctl.stop( invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) break # check for last access timeout if client._last_access is None: continue delta = now - client._last_access if settings.MJPG_CLIENT_IDLE_TIMEOUT and delta > settings.MJPG_CLIENT_IDLE_TIMEOUT: logging.debug( 'mjpg client for camera %(camera_id)s on port %(port)s has been idle for %(timeout)s seconds, removing it' % { 'camera_id': camera_id, 'port': port, 'timeout': settings.MJPG_CLIENT_IDLE_TIMEOUT }) client.close() continue
def _check_mounts(): logging.debug('checking SMB mounts...') stop, start = update_mounts() if stop: motionctl.stop() if start: motionctl.start() io_loop = ioloop.IOLoop.instance() io_loop.add_timeout(datetime.timedelta(seconds=settings.MOUNT_CHECK_INTERVAL), _check_mounts)
def _garbage_collector(): logging.debug("running garbage collector for mjpg clients...") io_loop = ioloop.IOLoop.instance() io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector) now = datetime.datetime.utcnow() for client in MjpgClient.clients.values(): camera_id = client._camera_id port = client._port # check for last jpg moment timeout last_jpg_moment = MjpgClient.last_jpg_moment.get(camera_id) if last_jpg_moment is None: MjpgClient.last_jpg_moment[camera_id] = now continue if client.closed(): continue delta = now - last_jpg_moment delta = delta.days * 86400 + delta.seconds if delta > settings.MJPG_CLIENT_TIMEOUT: logging.error( "mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s" % {"camera_id": camera_id, "port": port} ) motionctl.stop(invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) break # check for last access timeout last_access = MjpgClient.last_access.get(camera_id) if last_access is None: continue delta = now - last_access delta = delta.days * 86400 + delta.seconds if settings.MJPG_CLIENT_IDLE_TIMEOUT and delta > settings.MJPG_CLIENT_IDLE_TIMEOUT: logging.debug( "mjpg client for camera %(camera_id)s on port %(port)s has been idle for %(timeout)s seconds, removing it" % {"camera_id": camera_id, "port": port, "timeout": settings.MJPG_CLIENT_IDLE_TIMEOUT} ) client.close() continue
def run(): import cleanup import motionctl import motioneye import smbctl import thumbnailer import tornado.ioloop configure_signals() logging.info('hello! this is motionEye server %s' % motioneye.VERSION) test_requirements() if settings.SMB_SHARES: stop, start = smbctl.update_mounts() # @UnusedVariable if start: start_motion() else: start_motion() start_cleanup() start_wsswitch() if settings.THUMBNAILER_INTERVAL: start_thumbnailer() application.listen(settings.PORT, settings.LISTEN) logging.info('server started') tornado.ioloop.IOLoop.instance().start() logging.info('server stopped') if thumbnailer.running(): thumbnailer.stop() logging.info('thumbnailer stopped') if cleanup.running(): cleanup.stop() logging.info('cleanup stopped') if motionctl.running(): motionctl.stop() logging.info('motion stopped') if settings.SMB_SHARES: smbctl.umount_all() logging.info('SMB shares unmounted') logging.info('bye!')
def _check_mounts(): import motionctl logging.debug('checking SMB mounts...') stop, start = update_mounts() if stop: motionctl.stop() if start: motionctl.start() io_loop = IOLoop.instance() io_loop.add_timeout(datetime.timedelta(seconds=settings.MOUNT_CHECK_INTERVAL), _check_mounts)
def _garbage_collector(): logging.debug('running garbage collector for mjpg clients...') now = datetime.datetime.utcnow() for client in MjpgClient.clients.values(): camera_id = client._camera_id port = client._port # check for last jpg moment timeout last_jpg_moment = MjpgClient.last_jpg_moment.get(camera_id) if last_jpg_moment is None: MjpgClient.last_jpg_moment[camera_id] = now continue if client.closed(): continue delta = now - last_jpg_moment delta = delta.days * 86400 + delta.seconds if delta > settings.MJPG_CLIENT_TIMEOUT: logging.error('mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s' % { 'camera_id': camera_id, 'port': port}) motionctl.stop() # this will close all the mjpg clients motionctl.start() break # check for last access timeout last_access = MjpgClient.last_access.get(camera_id) if last_access is None: continue delta = now - last_access delta = delta.days * 86400 + delta.seconds if delta > settings.MJPG_CLIENT_TIMEOUT: logging.debug('mjpg client for camera %(camera_id)s on port %(port)s timed out' % { 'camera_id': camera_id, 'port': port}) client.close() continue io_loop = ioloop.IOLoop.instance() io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector)
def on_close(self): logging.debug('connection closed for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id}) if MjpgClient.clients.pop(self._camera_id, None): logging.debug('mjpg client for camera %(camera_id)s on port %(port)s removed' % { 'port': self._port, 'camera_id': self._camera_id}) if getattr(self, 'error', None) and self.error.errno != errno.ECONNREFUSED: now = time.time() if now - MjpgClient._last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT: logging.error('connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id}) motionctl.stop(invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) MjpgClient._last_erroneous_close_time = now
def _garbage_collector(): logging.debug('running garbage collector for mjpg clients...') io_loop = IOLoop.instance() io_loop.add_timeout(datetime.timedelta(seconds=settings.MJPG_CLIENT_TIMEOUT), _garbage_collector) now = time.time() for camera_id, client in MjpgClient.clients.items(): port = client._port # check for jpeg frame timeout if not client._last_jpg_times: client._last_jpg_times.append(now) last_jpg_time = client._last_jpg_times[-1] if client.closed(): continue delta = now - last_jpg_time if delta > settings.MJPG_CLIENT_TIMEOUT: logging.error('mjpg client timed out receiving data for camera %(camera_id)s on port %(port)s' % { 'camera_id': camera_id, 'port': port}) if settings.MOTION_RESTART_ON_ERRORS: motionctl.stop(invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) break # check for last access timeout if client._last_access is None: continue delta = now - client._last_access if settings.MJPG_CLIENT_IDLE_TIMEOUT and delta > settings.MJPG_CLIENT_IDLE_TIMEOUT: logging.debug('mjpg client for camera %(camera_id)s on port %(port)s has been idle for %(timeout)s seconds, removing it' % { 'camera_id': camera_id, 'port': port, 'timeout': settings.MJPG_CLIENT_IDLE_TIMEOUT}) client.close() continue
def on_close(self): logging.debug('connection closed for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id}) if MjpgClient.clients.pop(self._camera_id, None): MjpgClient.last_access.pop(self._camera_id, None) MjpgClient.last_jpg_moment.pop(self._camera_id, None) logging.debug('mjpg client for camera %(camera_id)s on port %(port)s removed' % { 'port': self._port, 'camera_id': self._camera_id}) if getattr(self, 'error', None): now = time.time() if now - MjpgClient.last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT: logging.error('connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id}) motionctl.stop() # this will close all the mjpg clients motionctl.start() MjpgClient.last_erroneous_close_time = now
def on_close(self): logging.debug( 'connection closed for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id }) if MjpgClient.clients.pop(self._camera_id, None): MjpgClient.last_access.pop(self._camera_id, None) MjpgClient.last_jpg_moment.pop(self._camera_id, None) logging.debug( 'mjpg client for camera %(camera_id)s on port %(port)s removed' % { 'port': self._port, 'camera_id': self._camera_id }) if getattr(self, 'error', None) and self.error.errno != errno.ECONNREFUSED: now = time.time() if now - MjpgClient.last_erroneous_close_time < settings.MJPG_CLIENT_TIMEOUT: logging.error( 'connection problem detected for mjpg client for camera %(camera_id)s on port %(port)s' % { 'port': self._port, 'camera_id': self._camera_id }) motionctl.stop( invalidate=True) # this will close all the mjpg clients motionctl.start(deferred=True) MjpgClient.last_erroneous_close_time = now # remove the cached picture MjpgClient.last_jpgs.pop(self._camera_id, None)
def run(): import cleanup import mjpgclient import motionctl import motioneye import smbctl import thumbnailer import wsswitch configure_signals() logging.info('hello! this is motionEye server %s' % motioneye.VERSION) test_requirements() if settings.SMB_SHARES: stop, start = smbctl.update_mounts() # @UnusedVariable if start: start_motion() else: start_motion() if settings.CLEANUP_INTERVAL: cleanup.start() logging.info('cleanup started') wsswitch.start() logging.info('wsswitch started') if settings.THUMBNAILER_INTERVAL: thumbnailer.start() logging.info('thumbnailer started') if settings.MJPG_CLIENT_TIMEOUT: mjpgclient.start() logging.info('mjpg client garbage collector started') if settings.SMB_SHARES: smbctl.start() logging.info('smb mounts started') template.add_context('static_path', settings.BASE_PATH + '/static/') application = Application(handler_mapping, debug=False, log_function=_log_request, static_path=settings.STATIC_PATH, static_url_prefix='/static/') application.listen(settings.PORT, settings.LISTEN) logging.info('server started') IOLoop.instance().start() logging.info('server stopped') if thumbnailer.running(): thumbnailer.stop() logging.info('thumbnailer stopped') if cleanup.running(): cleanup.stop() logging.info('cleanup stopped') if motionctl.running(): motionctl.stop() logging.info('motion stopped') if settings.SMB_SHARES: smbctl.stop() logging.info('smb mounts stopped') logging.info('bye!')
def run(): import cleanup import motionctl import motioneye import smbctl import thumbnailer import tornado.ioloop configure_signals() logging.info("hello! this is motionEye server %s" % motioneye.VERSION) test_requirements() if settings.SMB_SHARES: stop, start = smbctl.update_mounts() # @UnusedVariable if start: start_motion() else: start_motion() start_cleanup() start_wsswitch() if settings.THUMBNAILER_INTERVAL: start_thumbnailer() template.add_context("static_path", settings.BASE_PATH + "/static/") application = Application( handler_mapping, debug=False, log_function=_log_request, static_path=settings.STATIC_PATH, static_url_prefix="/static/", ) application.listen(settings.PORT, settings.LISTEN) logging.info("server started") tornado.ioloop.IOLoop.instance().start() logging.info("server stopped") if thumbnailer.running(): thumbnailer.stop() logging.info("thumbnailer stopped") if cleanup.running(): cleanup.stop() logging.info("cleanup stopped") if motionctl.running(): motionctl.stop() logging.info("motion stopped") if settings.SMB_SHARES: smbctl.umount_all() logging.info("SMB shares unmounted") logging.info("bye!")
def run(): import cleanup import mjpgclient import motionctl import motioneye import smbctl import tasks import wsswitch configure_signals() logging.info('hello! this is motionEye server %s' % motioneye.VERSION) test_requirements() make_media_folders() if settings.SMB_SHARES: stop, start = smbctl.update_mounts() # @UnusedVariable if start: start_motion() else: start_motion() if settings.CLEANUP_INTERVAL: cleanup.start() logging.info('cleanup started') wsswitch.start() logging.info('wsswitch started') tasks.start() logging.info('tasks started') if settings.MJPG_CLIENT_TIMEOUT: mjpgclient.start() logging.info('mjpg client garbage collector started') if settings.SMB_SHARES: smbctl.start() logging.info('smb mounts started') template.add_context('static_path', settings.BASE_PATH + '/static/') application = Application(handler_mapping, debug=False, log_function=_log_request, static_path=settings.STATIC_PATH, static_url_prefix='/static/') application.listen(settings.PORT, settings.LISTEN) logging.info('server started') io_loop = IOLoop.instance() io_loop.start() logging.info('server stopped') tasks.stop() logging.info('tasks stopped') if cleanup.running(): cleanup.stop() logging.info('cleanup stopped') if motionctl.running(): motionctl.stop() logging.info('motion stopped') if settings.SMB_SHARES: smbctl.stop() logging.info('smb mounts stopped') logging.info('bye!')
def run(): import cleanup import mjpgclient import motionctl import motioneye import smbctl import tasks import wsswitch configure_signals() logging.info('hello! this is motionEye server %s' % motioneye.VERSION) test_requirements() make_media_folders() if settings.SMB_SHARES: stop, start = smbctl.update_mounts() # @UnusedVariable if start: start_motion() else: start_motion() if settings.CLEANUP_INTERVAL: cleanup.start() logging.info('cleanup started') wsswitch.start() logging.info('wsswitch started') tasks.start() logging.info('tasks started') if settings.MJPG_CLIENT_TIMEOUT: mjpgclient.start() logging.info('mjpg client garbage collector started') if settings.SMB_SHARES: smbctl.start() logging.info('smb mounts started') template.add_context('static_path', 'static/') application = Application(handler_mapping, debug=False, log_function=_log_request, static_path=settings.STATIC_PATH, static_url_prefix='/static/') if settings.SSL_PORT > 0: application.listen(settings.SSL_PORT, settings.LISTEN, ssl_options={ "certfile": settings.SSL_CERT, "keyfile": settings.SSL_KEY, }) logging.info('https server started on port: %s' % settings.SSL_PORT) application.listen(settings.PORT, settings.LISTEN) logging.info('http server started ono port: %s' % settings.PORT) io_loop = IOLoop.instance() # we need to reset the loop's PID to fix PID checks when running in daemon mode io_loop._pid = os.getpid() io_loop.start() logging.info('server stopped') tasks.stop() logging.info('tasks stopped') if cleanup.running(): cleanup.stop() logging.info('cleanup stopped') if motionctl.running(): motionctl.stop() logging.info('motion stopped') if settings.SMB_SHARES: smbctl.stop() logging.info('smb mounts stopped') logging.info('bye!')