Пример #1
0
    def StartModules(self):

        self.LogConsole("Starting....")

        if not len(self.LoadOrder):
            self.LogInfo("Error, nothing to start.")
            return False
        ErrorOccured = False
        for Module in reversed(self.LoadOrder):
            try:
                if self.CachedConfig[Module]["enable"]:
                    if not multi_instance:
                        # check that module is not loaded already, if it is then force it (hard) to unload
                        attempts = 0
                        while True:
                            if MySupport.IsRunning(
                                    prog_name=self.CachedConfig[Module]
                                ["module"],
                                    log=self.log,
                                    multi_instance=multi_instance):
                                # if loaded then kill it
                                if attempts >= 4:
                                    # kill it
                                    if not self.UnloadModule(
                                            self.ModulePath,
                                            self.CachedConfig[Module]
                                        ["module"],
                                            pid=None,
                                            HardStop=True,
                                            UsePID=False):
                                        self.LogInfo("Error killing " +
                                                     self.CachedConfig[Module]
                                                     ["module"])
                                else:
                                    attempts += 1
                                    time.sleep(1)
                            else:
                                break

                    if not self.LoadModule(
                            self.ModulePath,
                            self.CachedConfig[Module]["module"],
                            args=self.CachedConfig[Module]["args"]):
                        self.LogInfo("Error starting " + Module)
                        ErrorOccured = True
                    if not self.CachedConfig[Module][
                            "postloaddelay"] == None and self.CachedConfig[
                                Module]["postloaddelay"] > 0:
                        time.sleep(self.CachedConfig[Module]["postloaddelay"])
            except Exception as e1:
                self.LogInfo("Error starting module " + Module + " : " +
                             str(e1),
                             LogLine=True)
                return False
        return not ErrorOccured
Пример #2
0
    HelpStr = '\npython genlog.py -a <IP Address or localhost> -f <outputfile> -c <config file path>\n'

    try:
        ConfigFilePath = ProgramDefaults.ConfPath
        console = SetupLogger("genlog_console", log_file="", stream=True)

        port, loglocation, multi_instance = MySupport.GetGenmonInitInfo(
            ConfigFilePath, log=console)

        if not MySupport.PermissionsOK():
            console.error(
                "You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting."
            )
            sys.exit(2)

        if MySupport.IsRunning(os.path.basename(__file__),
                               multi_instance=multi_instance):
            console.error("The program %s is already loaded" %
                          os.path.basename(__file__))
            sys.exit(2)

        opts, args = getopt.getopt(
            sys.argv[1:], "ha:f:c:",
            ["help", "address=", "filename=", "configpath="])
    except getopt.GetoptError:
        console.error(HelpStr)
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            console.error(HelpStr)
            sys.exit()