def check_app(name, exe_name=None, window_name=None, service_name=None): """Check if a program or service is running :param name: common name for the process. :param exe_name: executable name of the process. :param window_name: title of the process. :param service_name: name of the service. """ try: if exe_name is not None: handler = StartStop() handler.exeName = exe_name res = handler.probeProcess() elif window_name is not None: handler = CMDStartStop() handler.windowName = window_name res = handler.probeProcess() elif service_name is not None: handler = StartStop() handler.serviceName = service_name res = handler.probeService() else: raise Exception("exe_name, window_name, or service_name should be " "given.") except: res = EXCEPTION pStdout(name, res)
def stop_executable(name, process_name, cmd=False): """Stop an executable :param name: common name for the program :param process_name: name of the process :param cmd: boolean indicating if it is a cmd window (e.g. Python) """ try: logger.info('Stopping %s...', name) if not cmd: handler = StartStop() handler.exeName = process_name else: handler = CMDStartStop() handler.windowName = process_name result = handler.stopProcess() logger.info('Status: %s', status(result)) except: logger.exception('An exception was generated while stopping %s!', name)
def start(): logger.info("Starting User-Mode applications...") HS_ROOT = "%s" % os.getenv("HISPARC_ROOT") if HS_ROOT == "": logger.critical("FATAL: environment variable HISPARC_ROOT not set!") return configFile = os.path.join(HS_ROOT, "persistent/configuration/config.ini") config = ConfigParser.ConfigParser() config.read(configFile) try: logger.info("Starting MySQL...") datapath = os.path.join(HS_ROOT, "persistent/data/mysql") binlogs = glob.glob(os.path.join(datapath, "mysql-bin.*")) if binlogs: logger.info("Removing stale MySQL binary logs...") for f in binlogs: os.remove(f) binary = "mysqld.exe" # Were the extra quotes in the path string required? program = os.path.join(HS_ROOT, "user/mysql/bin", binary) handler = StartStop() handler.exeName = binary # Check if MySQL is already running res = handler.probeProcess() if res == RUNNING: delay_monitor = 0 else: delay_monitor = 10 handler.ShowWindow = win32con.SW_HIDE handler.command = program handler.currentDirectory = HS_ROOT handler.title = "MySQL server" res = handler.startProcess() if res == RUNNING: time.sleep(5) # check run-status again res = handler.probeProcess() logger.info("Status: %s", status(res)) except: logger.exception("An exception was generated while starting MySQL") try: logger.info("Starting HiSPARC Detector...") if config.getboolean("Detector", "Enabled"): handler = StartStop() handler.exeName = "HiSPARC DAQ.exe" handler.currentDirectory = os.path.join(HS_ROOT, "user/hisparcdaq") handler.command = os.path.join(HS_ROOT, "user/hisparcdaq/HiSPARC DAQ.exe") res = handler.startProcess() else: res = DISABLED logger.info("Status: %s", status(res)) except: logger.exception("An exception was generated while starting " "HiSPARC Detector") try: logger.info("Starting HiSPARC Weather...") if config.getboolean("Weather", "Enabled"): handler = StartStop() handler.exeName = "HiSPARC Weather Station.exe" handler.currentDirectory = os.path.join(HS_ROOT, "user/hisparcweather") handler.command = os.path.join(HS_ROOT, "user/hisparcweather", "HiSPARC Weather Station.exe") result = handler.startProcess() else: result = DISABLED logger.info("Status: %s", status(result)) except: logger.exception("An exception was generated while starting " "HiSPARC Weather") # Pause to let MySQL start completely if it was not already running time.sleep(delay_monitor) cmd = '%s/user/startstop/runmanually.bat "{name}" "{path}" {cmd}' % HS_ROOT try: logger.info("Starting HiSPARC Monitor...") handler = CMDStartStop() handler.windowName = "HiSPARC Monitor" handler.title = "Start HiSPARC Monitor" handler.currentDirectory = os.path.join(HS_ROOT, "user/hsmonitor") handler.command = cmd.format(name=handler.windowName, path=r"\user\hsmonitor", cmd="HsMonitor.py") result = handler.startProcess() logger.info("Status: %s", status(result)) except: logger.exception("An exception was generated while starting " "HiSPARC Monitor") try: logger.info("Starting HiSPARC Updater...") handler = CMDStartStop() handler.windowName = "HiSPARC Updater" handler.title = "Start HiSPARC Updater" handler.currentDirectory = os.path.join(HS_ROOT, "user/updater") handler.command = cmd.format(name=handler.windowName, path=r"\user\updater", cmd="Update.py") result = handler.startProcess() logger.info("Status: %s", status(result)) except: logger.exception("An exception was generated while starting the " "HiSPARC Updater")