Example #1
0
def setup_apache():

    template = os.path.join(
        utils.fabfile_templates_root(),
        "apache.%s.conf" % env.config_type,
    )

    # require that apache is set up with modwsgi
    fabtools.require.apache.server()
    fabtools.require.deb.package('libapache2-mod-wsgi')
    fabtools.require.apache.module_enabled("wsgi")
    fabtools.require.apache.module_enabled("rewrite")
    fabtools.require.apache.module_enabled("expires")

    # enable site with the given configuration
    fabtools.require.apache.site(
        env.site_name,
        template_source=template,
        site_name=env.site_name,
        site_root=os.path.join(env.web_path),
    )
    fabtools.require.apache.disabled('000-default')

    # set permissions so that apache can read/write
    sudo("chgrp -R www-data %s" % env.remote_path)
    sudo("chmod -R g+w %s" % env.remote_path)
Example #2
0
def setup_shell_environment():
    """setup the shell environment on the remote machine"""

    # change into the /vagrant directory by default
    template = os.path.join(
        utils.fabfile_templates_root(),
        '.bash_profile',
    )
    fabtools.require.files.file(
        path="/home/vagrant/.bash_profile",
        contents="cd /vagrant",
    )
Example #3
0
def setup_bash():
    """setup the shell environment on the remote machine"""

    # move our template over
    template = os.path.join(utils.fabfile_templates_root(), "bash_profile")
    context = locals()
    context.update(env)
    fabtools.require.files.template_file(
        path="/home/%s/.bash_profile" % env.user,
        template_source=template,
        context=context,
    )
Example #4
0
def setup_analysis():
    """prepare analysis environment"""
    with vagrant_settings(env.host_string):
        
        # write a analysis.ini file that has the provider so we can
        # easily distinguish between development and production
        # environments when we run our analysis
        template = os.path.join(
            utils.fabfile_templates_root(), 
            "server_config.ini",
        )
        fabtools.require.files.template_file(
            path="/vagrant/server_config.ini",
            template_source=template,
            context=env,
        )
Example #5
0
def setup_django():
    """render settings and collectstatic
    """
    fabtools.files.upload_template(
        "django_local_settings.py",
        os.path.join(env.web_path, "/conf/settings/local.py"),
        context=env,
        use_jinja=True,
        template_dir=utils.fabfile_templates_root(),
    )

    # only collectstatic on non-dev environments- in dev, the dev
    # server handles staticfiles and having things in $root/static
    # confuses compressor
    if env.config_type != 'dev':
        with cd(env.remote_path):
            run("./manage.py collectstatic --noinput")
Example #6
0
def setup_analysis():
    """prepare analysis environment"""
        
    # write a analysis.ini file that has the provider so we can
    # easily distinguish between development and production
    # environments when we run our analysis
    template = os.path.join(
        utils.fabfile_templates_root(), 
        "server_config.ini",
    )
    fabtools.require.files.template_file(
        path="/vagrant/server_config.ini",
        template_source=template,
        context=env,
    )

    # create a data directory where all of the analysis and raw
    # data is stored. 
    data_dir = "/vagrant/data"
    fabtools.require.files.directory(data_dir)
Example #7
0
def setup_bash():
    """setup the shell environment on the remote machine"""

    # download the django bash completion niceness
    completions_directory="/home/%s/.bash_completion.d" % env.user
    fabtools.require.directory(completions_directory)
    fabtools.require.files.file(
        os.path.join(completions_directory, 'django'),
        url=(
            "https://raw.githubusercontent.com"
            "/django/django/master/extras/django_bash_completion"
        ),
    )

    # move our template over
    template = os.path.join(utils.fabfile_templates_root(), "bash_profile")
    context = locals()
    context.update(env)
    fabtools.require.files.template_file(
        path="/home/%s/.bash_profile" % env.user,
        template_source=template,
        context=context,
    )
Example #8
0
def setup_django(do_rsync=True):
    """setup django"""

    # http://stackoverflow.com/a/19536667/564709
    if isinstance(do_rsync, (str, unicode,)):
        do_rsync = bool(strtobool(do_rsync))
        
    with vagrant_settings(env.host_string):

        # open up and listen to port 8000
        sudo("iptables -A INPUT -p tcp --dport 8000 -j ACCEPT")

        # extract necessary configuration variables from INI file
        parser = utils.get_config_parser()
        mysql_root_password = parser.get('mysql', 'root_password')
        django_username = parser.get('mysql', 'django_root_username')
        django_password = parser.get('mysql', 'django_root_password')
        django_db = parser.get('mysql', 'django_database')

        # setup mysql
        fabtools.require.mysql.server(password=mysql_root_password)
        with settings(mysql_user='root', mysql_password=mysql_root_password):
            fabtools.require.mysql.user(django_username, django_password)
            fabtools.require.mysql.database(django_db,owner=django_username)


        # collect the static files
        with cd("/vagrant/Web"):
            run("./manage.py collectstatic --noinput")

        # rsync directory to get all models, views, etc into the
        # /srv/www directory.
        #
        # TODO: Use a soft link to the figures/templates directory to
        # avoid unnecessary rsyncing of data from analysis?
        site_name = "movievsmovie.datasco.pe"
        web_dir = "Web"
        site_root = os.path.join("/srv", "www", site_name, web_dir)
        fabtools.require.directory(site_root, owner="www-data", use_sudo=True)
        if do_rsync:
            sudo("rsync -avC --exclude='*.hg' /vagrant/%s %s" % (
                web_dir, os.path.dirname(site_root)
            ))

        # write the local django settings. since local.py is listed in
        # the .hgignore, the -C option to rsync must ignore it. this
        # needs to go AFTER rsyncing
        for root_dir in ["/vagrant/" + web_dir, site_root]:
            # make sure the dir exists (for the site_root one)
            target_dir = root_dir+"/Web/settings/"
            fabtools.require.directory(target_dir, owner="www-data", use_sudo=True)
            # use_sudo is necessary (for the site_root one)
            fabtools.require.files.template_file(
                path=root_dir+"/Web/settings/local.py",
                template_source=os.path.join(
                    utils.fabfile_templates_root(), "django_settings.py"
                ),
                context={
                    "django_db": django_db,
                    "django_username": django_username,
                    "django_password": django_password,
                },
                use_sudo=True,
            )

        # make sure permissions are set up properly
        #sudo("chmod -R a+w %s" % site_root)
        sudo("chmod -R g+w %s" % site_root)
        sudo("chgrp -R www-data %s" % site_root)
            
        # make sure database is up and running
        with cd("/vagrant/Web"):
            run("./manage.py syncdb --noinput")
            run("./manage.py migrate")


        # setup apache
        # fabtools.require.apache.module_enabled("mod_wsgi") # __future__
        config_filename = os.path.join(
            utils.fabfile_templates_root(), 
            "apache.conf",
        )
        fabtools.require.apache.site(
            'movie.vs.movie.datasco.pe',
            template_source=config_filename,
            wsgi_application_group=r"%{GLOBAL}",
            site_name=site_name,
            site_root=site_root,
        )
        fabtools.require.apache.disabled('default')
Example #9
0
def setup_django(do_rsync=True):
    """setup django"""
        
    with vagrant_settings(env.host_string):

        # extract necessary configuration variables from INI file
        parser = utils.get_config_parser()
        mysql_root_password = parser.get('mysql', 'root_password')
        django_username = parser.get('mysql', 'django_root_username')
        django_password = parser.get('mysql', 'django_root_password')
        django_db = parser.get('mysql', 'django_database')
        facebook_id = parser.get('social', 'FACEBOOK_APP_ID')

        # setup mysql
        fabtools.require.mysql.server(password=mysql_root_password)
        with settings(mysql_user='root', mysql_password=mysql_root_password):
            fabtools.require.mysql.user(django_username, django_password)
            fabtools.require.mysql.database(django_db,owner=django_username)

        # write the local django settings. since local.py is listed in
        # the .hgignore, the -C option to rsync must ignore it. this
        # needs to go AFTER rsyncing

        # rsync directory to get all models, views, etc into the
        # /srv/www directory.
        #
        # TODO: Use a soft link to the figures/templates directory to
        # avoid unnecessary rsyncing of data from analysis?
        site_name = "chicagoenergy.datascopeanalytics.com"
        web_dir = "Map"
        site_root = os.path.join("/srv", "www", site_name, web_dir)
        fabtools.require.directory(site_root, owner="www-data", use_sudo=True)
        if do_rsync:
            sudo("rsync -avC --exclude='*.hg' /vagrant/%s %s" % (
                web_dir, os.path.dirname(site_root)
            ))


        for root_dir in ["/vagrant/" + web_dir, site_root]:
            # make sure the dir exists (for the site_root one)
            target_dir = root_dir+"/Map/settings/"
            fabtools.require.directory(target_dir, owner="www-data", use_sudo=True)
            # use_sudo is necessary (for the site_root one)
            fabtools.require.files.template_file(
                path=root_dir+"/Map/settings/local.py",
                template_source=os.path.join(
                    utils.fabfile_templates_root(), "django_settings.py"
                ),
                context={
                    "django_db": django_db,
                    "django_username": django_username,
                    "django_password": django_password,
                    "FACEBOOK_APP_ID": facebook_id,
                },
                use_sudo=True,
            )

        # collect the static files
        with cd("/vagrant/Map"):
            run("./manage.py collectstatic --noinput")

        # make sure permissions are set up properly
        #sudo("chmod -R a+w %s" % site_root)
        sudo("chmod -R g+w %s" % site_root)
        sudo("chgrp -R www-data %s" % site_root)

        # # make sure permissions are set up properly
        # #sudo("chmod -R a+w %s" % site_root)
        # sudo("chmod -R g+w %s" % site_root)
        # sudo("chgrp -R www-data %s" % site_root)
            
        # make sure database is up and running
        with cd("/vagrant/Map"):
            run("./manage.py syncdb --noinput")
            run("./manage.py migrate")

        # setup apache
        # fabtools.require.apache.module_enabled("mod_wsgi") # __future__
        config_filename = os.path.join(
            utils.fabfile_templates_root(), 
            "apache.conf",
        )
        fabtools.require.apache.site(
            'chicagoenergy.datascopeanalytics.com',
            template_source=config_filename,
            wsgi_application_group=r"%{GLOBAL}",
            site_name=site_name,
            site_root=site_root,
        )
        fabtools.require.apache.disabled('default')