Esempio n. 1
0
    def status(self):
        """
        check the MongoDB status
        returns a json object with status: and pid: command
        """

        result = find_process("mongod")

        if result is None:
            state = dotdict({
                "status": "error",
                "message": "No mongod running",
                "output": None
            })
            output = None
        else:
            state = dotdict({
                "status": "ok",
                "message": "running",
                "output": None
            })
            output = {}
            for p in result:
                p = dotdict(p)

                process = {"pid": str(p.pid), "command": p.command}
                output[str(p.pid)] = process
            state["output"] = output
        return state
Esempio n. 2
0
    def status(self):
        """
        check the MongoDB status
        returns a json object with status: and pid: command
        """

        if platform.lower() == 'win32':
            script = """
            tasklist /FO LIST /FI "IMAGENAME eq mongod.exe"
            """
            output = Script.run(script)
            result = {}
            for row in output.split('\n'):
                if ': ' in row:
                    key, value = row.split(': ')
                    result[key.strip()] = value.strip()

            if result is None:
                state = dotdict({
                    "status": "error",
                    "message": "No mongod running",
                    "output": None
                })
            else:
                state = dotdict({
                    "status": "ok",
                    "message": "running",
                    "output": None
                })
                process = {
                    "pid": str(result['PID']),
                    "command": result['Image Name']
                }
                output = {}
                output[str()] = process
                state["output"] = output

        else:
            result = find_process("mongod")
            if result is None:
                state = dotdict({
                    "status": "error",
                    "message": "No mongod running",
                    "output": None
                })
                output = None
            else:
                state = dotdict({
                    "status": "ok",
                    "message": "running",
                    "output": None
                })
                output = {}
                for p in result:
                    p = dotdict(p)
                    process = {"pid": str(p.pid), "command": p.command}
                    output[str(p.pid)] = process
                state["output"] = output
        return state
Esempio n. 3
0
    def status(self):
        """
        check the MongoDB status
        returns a json object with status: and pid: command
        """

        mode = self.data['MODE']

        if mode == 'docker':
            from cloudmesh.mongo.MongoDocker import MongoDocker
            mongo = MongoDocker()
            state = mongo.status()

        if platform.lower() == 'win32':
            script = """
            tasklist /FO LIST /FI "IMAGENAME eq mongod.exe"
            """
            output = Script.run(script)
            if 'INFO: No tasks are running which match the specified criteria.' in output:
                result = None
            else:
                result = {}
                for row in output.split('\n'):
                    if ': ' in row:
                        key, value = row.split(': ')
                        result[key.strip()] = value.strip()

            if result is None:
                state = dotdict({
                    "status": "error",
                    "message": "No mongod running",
                    "output": None
                })
            else:
                state = dotdict({
                    "status": "ok",
                    "message": "running",
                    "output": None
                })
                process = {
                    "pid": str(result['PID']),
                    "command": result['Image Name']
                }
                output = {}
                #
                # TODO: there was a bug here, please check, it was only str()
                #
                output[str(result['PID'])] = process
                state["output"] = output

        else:
            result = find_process("mongod")
            if result is None:
                state = dotdict({
                    "status": "error",
                    "message": "No mongod running",
                    "output": None
                })
                output = None
            else:
                state = dotdict({
                    "status": "ok",
                    "message": "running",
                    "output": None
                })
                output = {}
                for p in result:
                    p = dotdict(p)
                    process = {"pid": str(p.pid), "command": p.command}
                    output[str(p.pid)] = process
                state["output"] = output
        return state