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_service(name, service_name): """Stop a service :param name: common name for printing :param service_name: name of the Service """ try: logger.info('Stopping %s Service', name) service_handler = StartStop() service_handler.serviceName = service_name result = service_handler.stopService() if result == 0: logger.info('Status: running') elif result == 1: logger.info('Status: stopped') else: logger.error('The service was not found!') except: logger.exception('An exception was generated while stopping %s', name)
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(): setLogMode(MODE_BOTH) log("\nStarting User-Mode applications...") HS_ROOT = "%s" % os.getenv("HISPARC_ROOT") if HS_ROOT == "": log("FATAL: environment variable HISPARC_ROOT not set!") return configFile = "%s/persistent/configuration/config.ini" % HS_ROOT config = ConfigParser.ConfigParser() config.read(configFile) try: # start MySQL log("Starting MySQL...") datapath = "%s/persistent/data/mysql" % HS_ROOT binlogs = glob.glob(os.path.join(datapath, "mysql-bin.*")) if binlogs: log("Removing stale MySQL binary logs...") for f in binlogs: os.remove(f) binary = "mysqld.exe" exeBase = "%s/user/mysql/bin" % HS_ROOT program = '"%(exec)s/%(binary)s"' % {"exec": exeBase, "binary": binary} handler = StartStop() handler.exeName = binary 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() log("Status: " + status(res)) except: log("An exception was generated while starting MySQL: " + str(sys.exc_info()[1])) try: # start LabVIEW detector log("Starting LabVIEW detector...") if config.getboolean("Detector", "Enabled"): handler = StartStop() handler.exeName = "hisparcdaq.exe" handler.currentDirectory = "%s/user/hisparcdaq" % HS_ROOT handler.command = "%s/user/hisparcdaq/hisparcdaq.exe" % HS_ROOT res = handler.startProcess() else: res = DISABLED log("Status: " + status(res)) except: log("An exception was generated while starting LabVIEW detector: " + str(sys.exc_info()[1])) try: # start LabVIEW weather log("Starting LabVIEW weather...") if config.getboolean("Weather", "Enabled"): handler = StartStop() handler.exeName = "HiSPARC Weather Station.exe" handler.currentDirectory = "%s/user/hisparcweather" % HS_ROOT handler.command = "%s/user/hisparcweather/HiSPARC Weather Station.exe" % HS_ROOT res = handler.startProcess() else: res = DISABLED log("Status: " + status(res)) except: log("An exception was generated while starting LabVIEW weather: " + str(sys.exc_info()[1])) # Introduce a 20-second pause to let MySQL start completely time.sleep(20) try: # start HSMonitor log("Starting HSMonitor...") handler = CMDStartStop() handler.exeName = "python.exe" handler.title = "HISPARC MONITOR: hsmonitor" handler.currentDirectory = "%s/user/hsmonitor" % HS_ROOT handler.command = "%s/user/python/python.exe HsMonitor.py" % HS_ROOT res = handler.startProcess() log("Status: " + status(res)) except: log("An exception was generated while starting HSMonitor: " + str(sys.exc_info()[1])) try: # start updater log("Starting Updater...") handler = CMDStartStop() handler.exeName = "python.exe" handler.title = "HISPARC Updater: updater" handler.currentDirectory = "%s/user/updater" % HS_ROOT handler.command = "%s/user/python/python.exe Update.py" % HS_ROOT res = handler.startProcess() log("Status: " + status(res)) except: log("An exception was generated while starting the Updater: " + str(sys.exc_info()[1]))
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")