Exemplo n.º 1
0
 def shutdown_mongodb(self):
     """
     shutdown the MongoDB server
     linux and darwin have different way to shutdown the server, the common way is kill
     """
     script = 'kill -2 `pgrep mongo`'
     run = Script(script)
Exemplo n.º 2
0
    def set_auth(self):
        """
        add admin acount into the MongoDB admin database
        """

        script = """mongo --eval 'db.getSiblingDB("admin").createUser({user:"******",pwd:"%s",roles:[{role:"root",db:"admin"}]})'""" % (
            self.data['MONGO_USERNAME'], self.data['MONGO_PASSWORD'])
        run = Script(script)
Exemplo n.º 3
0
    def status(self):
        """
        check the MongoDB status
        """

        script = "ps -ax | grep mongo | fgrep -v grep"

        ps_output = Script(script)
        print(ps_output)
Exemplo n.º 4
0
    def restore(self, filename):
        """
        restore the backup data generated by dump
        :param data: the backup data folder
        """
        #
        # TODO: BUG: expand user
        #

        script = "mongorestore --authenticationDatabase admin -u {MONGO_USERNAME} -p " \
                 "{MONGO_PASSWORD} --gzip --archive={MONGO_HOME}/".format(**self.data)+filename+".gz"
        run = Script(script)
Exemplo n.º 5
0
 def run_mongodb(self, security=False):
     """
     start the MongoDB server
     """
     if security:
         script = "mongod --dbpath {MONGO_PATH}  --logpath {MONGO_LOG}/mongod.log --fork".format(
             **self.data)
     else:
         script = "mongod --auth --dbpath {MONGO_PATH} --logpath {MONGO_LOG}/mongod.log --fork".format(
             **self.data)
     print(script)
     run = Script(script)
Exemplo n.º 6
0
    def dump(self, filename):
        """
        dump the entire MongoDB database into output location
        :param output_location: the location to save the backup
        """
        #
        # TODO: BUG: expand user
        #

        script = "mongodump --authenticationDatabase admin --archive={MONGO_HOME}/".format(
            **self.data
        ) + filename + ".gz --gzip -u {MONGO_USERNAME} -p {MONGO_PASSWORD}".format(
            **self.data)
        run = Script(script)
Exemplo n.º 7
0
 def linux(self):
     # TODO UNTESTED
     """
     install MongoDB in Linux system (Ubuntu)
     """
     script = """
     sudo apt-get --yes install libcurl4 openssl
     mkdir -p {MONGO_PATH}
     mkdir -p {MONGO_HOME}
     mkdir -p {MONGO_LOG}
     wget -P /tmp/mongodb.tgz {MONGO_CODE}
     tar -zxvf /tmp/mongodb.tgz -C {LOCAL}/mongo --strip 1
         """.format(**self.data)
     installer = Script(script)
     SystemPath.add("{MONGO_HOME}/bin".format(**self.data))
Exemplo n.º 8
0
    def darwin(self, brew=False):
        """
        install MongoDB in Darwin system (Mac)
        """

        if brew:
            print("mongo installer via brew")
            Brew.install("mongodb")
            path = Shell.which("mongod")
            SystemPath.add("{path}".format(path=path))

        else:
            script = """
            mkdir -p {MONGO_PATH}
            mkdir -p {MONGO_HOME}
            mkdir -p {MONGO_LOG}
            curl -o /tmp/mongodb.tgz {MONGO_CODE}
            tar -zxvf /tmp/mongodb.tgz -C {LOCAL}/mongo --strip 1
            """.format(**self.data)
            installer = Script(script)
            SystemPath.add("{MONGO_HOME}/bin".format(**self.data))