Example #1
0
def build_server():
    """Build a complete functioning FOSSGIS server instance.

    Notes:

    The installed server will have QGIS from master set up on it and postgres
    installed with postgis and a template spatial database created. A default
    database called 'gis' will be created too.

        e.g.

            fab -H root@foo create_user
            fab -H foo build_server

        You need to run the create_user task separately to bootstrap the
        creation of your user on the remote host.
    """
    build_proj4()
    build_hdf5()
    create_postgis_1_5_db("gis")
    install_qgis2(gdal_from_source=True)
Example #2
0
def build_server():
    """Build a complete functioning FOSSGIS server instance.

    Notes:

    The installed server will have QGIS from master set up on it and postgres
    installed with postgis and a template spatial database created. A default
    database called 'gis' will be created too.

        e.g.

            fab -H root@foo create_user
            fab -H foo build_server

        You need to run the create_user task separately to bootstrap the
        creation of your user on the remote host.
    """
    build_proj4()
    build_hdf5()
    create_postgis_1_5_db('gis')
    install_qgis2(gdal_from_source=True)
Example #3
0
def setup_website():
    """Initialise or update the git clone.

    e.g. to update the server

    fab -H 1.1.1.1:111 remote setup_website

    or if you have configured env.hosts, simply

    fab remote setup_website
    """

    fabtools.require.postfix.server(env.repo_alias)
    fabtools.require.deb.package('libapache2-mod-wsgi')
    # Find out if the wsgi user exists and create it if needed e.g.
    fabtools.require.user(
        env.wsgi_user,
        create_group=env.wsgi_user,
        system=True,
        comment='System user for running the wsgi process under')

    if not exists(env.webdir):
        sudo('mkdir -p %s' % env.plugin_repo_path)
        sudo('chown %s.%s %s' % (env.user, env.user, env.webdir))

    # Clone and replace tokens in apache conf

    conf_file = (
        '%s/apache/%s.apache.conf' % (
            env.code_path, env.repo_alias))

    run(
        'cp %(conf_file)s.templ %(conf_file)s' % {
            'conf_file': conf_file})

    replace_tokens(conf_file)

    with cd('/etc/apache2/sites-available/'):
        if exists('%s.apache.conf' % env.repo_alias):
            sudo('a2dissite %s.apache.conf' % env.repo_alias)
            fastprint('Removing old apache2 conf', False)
            sudo('rm %s.apache.conf' % env.repo_alias)

        sudo('ln -s %s .' % conf_file)

    # wsgi user needs pg access to the db
    postgres.require_postgres_user(env.wsgi_user, env.wsgi_user)
    postgres.require_postgres_user('timlinux', 'timlinux')
    postgres.require_postgres_user('readonly', 'readonly')
    postgres.create_postgis_1_5_db('%s' % PROJECT_NAME, env.wsgi_user)
    grant_sql = 'grant all on schema public to %s;' % env.wsgi_user
    # assumption is env.repo_alias is also database name
    run('psql %s -c "%s"' % (env.repo_alias, grant_sql))
    grant_sql = (
        'GRANT ALL ON ALL TABLES IN schema public to %s;' % env.wsgi_user)
    # assumption is env.repo_alias is also database name
    run('psql %s -c "%s"' % (env.repo_alias, grant_sql))
    grant_sql = (
        'GRANT ALL ON ALL SEQUENCES IN schema public to %s;' % env.wsgi_user)
    run('psql %s -c "%s"' % (env.repo_alias, grant_sql))
    pwd_sql = 'ALTER USER timlinux WITH PASSWORD \'timlinux\';'
    pwd_sql = 'ALTER USER %s WITH PASSWORD \'%s\';' % (
        env.wsgi_user, env.wsgi_user)
    run('psql %s -c "%s"' % (env.repo_alias, pwd_sql))
    #with cd(env.code_path):
    # run the script to create the sites view
    #run('psql -f sql/3-site-view.sql %s' % env.repo_alias)

    # Add a hosts entry for local testing - only really useful for localhost
    hosts = '/etc/hosts'
    if not contains(hosts, env.repo_site_name):
        append(hosts, '127.0.0.1 %s' % env.repo_site_name, use_sudo=True)
    if not contains(hosts, 'www.' + env.repo_site_name):
        append(hosts,
               '127.0.0.1 %s' % 'www.' + env.repo_site_name,
               use_sudo=True)
        # Make sure mod rewrite is enabled
    sudo('a2enmod rewrite')
    # Enable the vhost configuration
    sudo('a2ensite %s.apache.conf' % env.repo_alias)

    # Check if apache configs are ok - script will abort if not ok
    sudo('/usr/sbin/apache2ctl configtest')
    sudo('a2dissite default')
    fabtools.require.service.restarted('apache2')

    #Setup a writable media dir for apache
    media_path = '%s/media' % env.code_path
    if not exists(media_path):
        sudo('mkdir %s' % media_path)
        sudo('chown %s.%s %s' % (env.wsgi_user, env.wsgi_user, env.code_path))