def daemon_diagnostic(): """ Generate a primative CLI daemon control menu and act on selections args : excepts : return : none """ # set kmotion_dir, remove /core from path kmotion_dir = os.getcwd()[:-5] # init the ramdisk dir init_core.init_ramdisk_dir(kmotion_dir) print """ kmotion manual daemon control ........""" while True: print """ The Options .... s: Start Daemons k: Kill Daemons r: Reload Daemon configs q: Quit ENTER: Refresh""" print_status() opt = raw_input('Option letter then ENTER to select : ') # 's' start daemons - lifted from 'kmotion.py' ------------------------- if opt == 's': if daemon_whip.all_daemons_running(): print '\nDaemons are already running ...' else: init_configs(kmotion_dir) daemon_whip.start_daemons() time.sleep(1) if daemon_whip.all_daemons_running(): print '\nDaemons have been started ...' else: print """ **** W A R N I N G **** Some daemons refused to start **** W A R N I N G ****""" # 'k' kill daemons ----------------------------------------------------- elif opt == 'k': print '\nDaemons are being killed ... this may take some time ...' daemon_whip.kill_daemons() # 'r' reload daemons --------------------------------------------------- elif opt == 'r': if daemon_whip.all_daemons_running(): print '\nDaemons config being reloaded ... this may take some time ...' init_configs(kmotion_dir) daemon_whip.reload_all_configs() else: print """ **** W A R N I N G **** Some daemons are NOT running so daemon configs have NOT been reloaded **** W A R N I N G ****""" # 'q' quit ------------------------------------------------------------- elif opt == 'q': print 'Quitting kmotion manual daemon control ...' print_status() break
def main(): """ Re-initialises the kmotion core and reload the kmotion daemon configs args : start|stop|reload on command line excepts : return : none """ # set kmotion_dir, remove /core from path kmotion_dir = os.getcwd()[:-5] option = sys.argv[1] # if 'stop' shutdown and exit here if option == 'stop': logger.log('stopping kmotion ...', 'CRIT') daemon_whip.kill_daemons() return elif option == 'start': logger.log('starting kmotion ...', 'CRIT') elif option == 'restart': logger.log('restarting kmotion ...', 'CRIT') elif option == 'status': print daemon_whip.daemon_status() return # check for any invalid motion processes p_objs = Popen('ps ax | grep -e [[:space:]]motion | grep -v \'\-c %s/core/motion_conf/motion.conf\'' % kmotion_dir, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) line = p_objs.stdout.readline() if line != '': logger.log('** CRITICAL ERROR ** kmotion failed to start ...', 'CRIT') logger.log('** CRITICAL ERROR ** Another instance of motion daemon has been detected', 'CRIT') raise exit_("""An instance of the motion daemon has been detected which is not under control of kmotion. Please kill this instance and ensure that motion is not started automatically on system bootup. This a known problem with Ubuntu 8.04 Reference Bug #235599.""") # init the ramdisk dir init_core.init_ramdisk_dir(kmotion_dir) # init the mutex's mutex.init_mutex(kmotion_dir, 'www_rc') mutex.init_mutex(kmotion_dir, 'kmotion_rc') mutex.init_mutex(kmotion_dir, 'logs') parser = mutex_kmotion_parser_rd(kmotion_dir) ramdisk_dir = parser.get('dirs', 'ramdisk_dir') max_feed = parser.getint('misc', 'max_feed') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.update_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): raise exit_('corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) try: # wrapping in a try - except because parsing data from kmotion_rc init_core.gen_vhost(kmotion_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): raise exit_('corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) # init motion_conf directory with motion.conf, thread1.conf ... init_motion.gen_motion_configs(kmotion_dir) # speed kmotion startup if daemon_whip.no_daemons_running(): daemon_whip.start_daemons() elif daemon_whip.all_daemons_running(): daemon_whip.reload_all_configs() else: daemon_whip.start_daemons() daemon_whip.reload_all_configs() time.sleep(1) # purge all fifo buffers, FIFO bug workaround :) purge_str = '#' * 1000 + '99999999' for fifo in ['fifo_func', 'fifo_ptz', 'fifo_ptz_preset', 'fifo_settings_wr']: pipeout = os.open('%s/www/%s' % (kmotion_dir, fifo), os.O_WRONLY) os.write(pipeout, purge_str) os.close(pipeout)
def daemon_diagnostic(): """ Generate a primative CLI daemon control menu and act on selections args : excepts : return : none """ # set kmotion_dir, remove /core from path kmotion_dir = os.getcwd()[:-5] # init the ramdisk dir init_core.init_ramdisk_dir(kmotion_dir) print """ kmotion manual daemon control ........""" while True: print """ The Options .... s: Start Daemons k: Kill Daemons r: Reload Daemon configs q: Quit ENTER: Refresh""" print_status() opt = raw_input('Option letter then ENTER to select : ') # 's' start daemons - lifted from 'kmotion.py' ------------------------- if opt == 's': if daemon_whip.all_daemons_running(): print '\nDaemons are already running ...' else: init_configs(kmotion_dir) daemon_whip.start_daemons() time.sleep(1) if daemon_whip.all_daemons_running(): print '\nDaemons have been started ...' else: print """ **** W A R N I N G **** Some daemons refused to start **** W A R N I N G ****""" # 'k' kill daemons ----------------------------------------------------- elif opt == 'k': print '\nDaemons are being killed ... this may take some time ...' daemon_whip.kill_daemons() # 'r' reload daemons --------------------------------------------------- elif opt == 'r': if daemon_whip.all_daemons_running(): print '\nDaemons config being reloaded ... this may take some time ...' init_configs(kmotion_dir) daemon_whip.reload_all_configs() else: print """ **** W A R N I N G **** Some daemons are NOT running so daemon configs have NOT been reloaded **** W A R N I N G ****""" # 'q' quit ------------------------------------------------------------- elif opt =='q': print 'Quitting kmotion manual daemon control ...' print_status() break
print 'kmotion_hkd2.py status : ' + text if status['motion']: text = '\033[1;32mRunning\033[1;37m' else: text= '\033[1;31mNot running\033[1;37m' print 'motion status : ' + text print opt = raw_input('Option letter then ENTER to select : ') if (opt == 's'): if(daemon_whip.daemons_running()): print '\n\033[1;32mDaemons already running ...\033[1;37m' else: daemon_whip.start_daemons() time.sleep(1) if(daemon_whip.daemons_running()): print '\n\033[1;32mDaemons have been started ...\033[1;37m' else: print '\n\033[1;31m*WARNING* Unable to start daemons ...\033[1;37m' elif (opt == 'k'): print '\n\033[1;31mStarting to kill daemons ...\033[1;37m' daemon_whip.kill_daemons() time.sleep(2) print '\033[1;31mDaemons have been killed ...\033[1;37m' elif (opt == 'r'): if(daemon_whip.daemons_running()): daemon_whip.config_reload()
def main(): """ Re-initialises the kmotion core and reload the kmotion daemon configs args : start|stop|reload on command line excepts : return : none """ # set kmotion_dir, remove /core from path kmotion_dir = os.getcwd()[:-5] option = sys.argv[1] # if 'stop' shutdown and exit here if option == 'stop': logger.log('stopping kmotion ...', 'CRIT') daemon_whip.kill_daemons() return elif option == 'start': logger.log('starting kmotion ...', 'CRIT') elif option == 'restart': logger.log('restarting kmotion ...', 'CRIT') # check for any invalid motion processes p_objs = Popen( 'ps ax | grep -e [[:space:]]motion | grep -v \'\-c %s/core/motion_conf/motion.conf\'' % kmotion_dir, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True) line = p_objs.stdout.readline() if line != '': logger.log('** CRITICAL ERROR ** kmotion failed to start ...', 'CRIT') logger.log( '** CRITICAL ERROR ** Another instance of motion daemon has been detected', 'CRIT') raise exit_( """An instance of the motion daemon has been detected which is not under control of kmotion. Please kill this instance and ensure that motion is not started automatically on system bootup. This a known problem with Ubuntu 8.04 Reference Bug #235599.""") # init the ramdisk dir init_core.init_ramdisk_dir(kmotion_dir) # init the mutex's mutex.init_mutex(kmotion_dir, 'www_rc') mutex.init_mutex(kmotion_dir, 'core_rc') mutex.init_mutex(kmotion_dir, 'logs') parser = mutex_core_parser_rd(kmotion_dir) ramdisk_dir = parser.get('dirs', 'ramdisk_dir') try: # wrapping in a try - except because parsing data from kmotion_rc init_core.update_rcs(kmotion_dir, ramdisk_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): raise exit_('corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) try: # wrapping in a try - except because parsing data from kmotion_rc init_core.gen_vhost(kmotion_dir) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): raise exit_('corrupt \'kmotion_rc\' : %s' % sys.exc_info()[1]) # init motion_conf directory with motion.conf, thread1.conf ... init_motion.gen_motion_configs(kmotion_dir) # speed kmotion startup if daemon_whip.no_daemons_running(): daemon_whip.start_daemons() elif daemon_whip.all_daemons_running(): daemon_whip.reload_all_configs() else: daemon_whip.start_daemons() daemon_whip.reload_all_configs() time.sleep(1) # purge all fifo buffers, FIFO bug workaround :) purge_str = '#' * 1000 + '99999999' for fifo in [ 'fifo_func', 'fifo_ptz', 'fifo_ptz_preset', 'fifo_settings_wr' ]: pipeout = os.open('%s/www/%s' % (kmotion_dir, fifo), os.O_WRONLY) os.write(pipeout, purge_str) os.close(pipeout)