def checker(): if ioloop._stopped: return if not motionctl.running() and motionctl.started() and config.get_enabled_local_motion_cameras(): try: logging.error("motion not running, starting it") motionctl.start() except Exception as e: logging.error("failed to start motion: %(msg)s" % {"msg": unicode(e)}, exc_info=True) ioloop.add_timeout(datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
def checker(): if io_loop._stopped: return if not motionctl.running() and motionctl.started() and config.get_enabled_local_motion_cameras(): try: logging.error('motion not running, starting it') motionctl.start() except Exception as e: logging.error('failed to start motion: %(msg)s' % { 'msg': unicode(e)}, exc_info=True) io_loop.add_timeout(datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
def checker(): #vector fix me: print ("Type:",type(io_loop)) if not io_loop: #if io_loop._stopped: print("Return...") return if not motionctl.running() and motionctl.started( ) and config.get_enabled_local_motion_cameras(): try: logging.error('motion not running, starting it') motionctl.start() except Exception as e: logging.error('failed to start motion: %(msg)s' % {'msg': str(e)}, exc_info=True) io_loop.add_timeout( datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
def start(deferred=False): import mjpgclient if deferred: io_loop = IOLoop.instance() io_loop.add_callback(start, deferred=False) global _started _started = True enabled_local_motion_cameras = config.get_enabled_local_motion_cameras() if running() or not enabled_local_motion_cameras: return logging.debug('starting motion') program = find_motion() if not program: raise Exception('motion executable could not be found') program, version = program # @UnusedVariable logging.debug('using motion binary "%s"' % program) motion_config_path = os.path.join(settings.CONF_PATH, 'motion.conf') motion_log_path = os.path.join(settings.LOG_PATH, 'motion.log') motion_pid_path = os.path.join(settings.RUN_PATH, 'motion.pid') args = [program, '-n', '-c', motion_config_path] args.append('-d') if settings.LOG_LEVEL <= logging.DEBUG: args.append('9') elif settings.LOG_LEVEL <= logging.WARN: args.append('5') elif settings.LOG_LEVEL <= logging.ERROR: args.append('4') else: # fatat, quiet args.append('1') log_file = open(motion_log_path, 'w') process = subprocess.Popen(args, stdout=log_file, stderr=log_file, close_fds=True, cwd=settings.CONF_PATH) # wait 2 seconds to see that the process has successfully started for i in xrange(20): # @UnusedVariable time.sleep(0.1) exit_code = process.poll() if exit_code is not None and exit_code != 0: raise Exception('motion failed to start') pid = process.pid # write the pid to file with open(motion_pid_path, 'w') as f: f.write(str(pid) + '\n') _disable_initial_motion_detection() # if mjpg client idle timeout is disabled, create mjpg clients for all cameras by default if not settings.MJPG_CLIENT_IDLE_TIMEOUT: logging.debug('creating default mjpg clients for local cameras') for camera in enabled_local_motion_cameras: mjpgclient.get_jpg(camera['@id'])