MongoDB

by zonmob
1 deployments · 0 still active · last rev. 9 months ago

Install MongoDB to a Linode. Can also be used as a library for other StackScripts.

Compatible with: CentOS 7, Debian 7, Ubuntu 14.04 LTS
						#!/usr/bin/env python

"""
MongoDB StackScript
    
    Author: Hieu Bui Duc <hieubd@zonmob.com>
    Version: 1.0.0.0
    Requirements:
        - ss://linode/python-library <ssinclude StackScriptID="3">

This StackScript both deploys as well as provides a library of functions for
the MongoDB. The functions in this StackScript are designed
to be run across the Linode Core Distributions:
    - Ubuntu
    - CentOS
    - Debian
    - Fedora
"""

import os
import subprocess
import sys

try: # we need to rename the included StackScript before we can import it
    os.rename("/root/ssinclude-3", "/root/pythonlib.py")
except:
    pass

import pythonlib

def mongodb_install(start=True):

    """Install repo package."""

    if pythonlib.distro is None:
        pythonlib.system_detect_distro()
    
    if pythonlib.distro['family'] == "debian":
        # mongodb key
        subprocess.call(['apt-key','adv','--keyserver','hkp://keyserver.ubuntu.com:80','--recv','EA312927'])

        # add mongodb to source list
        if pythonlib.distro['distname'] == "debian":
			os.system('echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list')
        elif pythonlib.distro['distname'] == "ubuntu":
			os.system('echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list')
        
        pythonlib.system_update()
    
    elif pythonlib.distro['family']=="redhat":
        with open("/etc/yum.repos.d/mongodb.repo", "w") as f:
            f.write("""[MongoDB]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1""")

    """Install MongoDB"""

    pythonlib.system_package_install("mongodb-org", False)

    if(pythonlib.distro['family']=="redhat" and start):
        subprocess.call(["chkconfig", "mongod", "on"])
	

def main():
    """Install MongoDB."""
    
    pythonlib.init()
    pythonlib.system_update()
    mongodb_install()

    pythonlib.end()


if __name__ == "__main__":
    sys.exit(main())