Exemplo n.º 1
0
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]))
Exemplo n.º 2
0
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")