Ecotrust / FishPass

FishPass - Web Frontend Interface for OptiPass
MIT License
2 stars 0 forks source link

FishPass

FishPass - Web Frontend Interface for OptiPass

Installation

Development Environment Only:

  1. Create a project Directory

  2. Clone marineplanner-core into it

  3. Load Fishpass into MP core:

    • cd marineplanner-core/apps
    • git clone https://github.com/Ecotrust/FishPass.git
  4. Configure app

    • LINUX
      • Copy apps/FishPass/scripts/configure_project.sh to scripts/configure_project.sh
    • MAC
      • Copy apps/FishPass/scripts/configure_project_mac.sh to scripts/configure_project.sh
    • make scripts/configure_project.sh executable
    • run your new configure_project script (may need to open in vim and enter :set fileformat=unix)
    • check that symlink to vagrant_provision.sh is created in marineplanner-core/scripts, not in marineplanner-core's root dir.
    • vagrant up
    • wait 30 minutes (or more if you don't have the base box or have a slow connection)
    • watch for errors and handle any that pop up - run vagrant provision to restart the provisioning process without losing all progress
    • run vagrant reload after installation to restart the server so all updates are applied
  5. log in to the server with vagrant ssh

    • cd /usr/local/apps/marineplanner-core/
    • source env/bin/activate
    • cd marineplanner
    • python manage.py enable_sharing --all
    • python manage.py runserver 0:8000
  6. Set your Local Settings

    • TODO: see fishpass/local_settings.py.template
  7. Import your data

    • To load initial data: dj loaddata /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/fixtures/initial_setup.json
    • To load an updated PAD file:
    • To load new FocusAreas:
      • run dj import_focus_areas ZIPFILE TYPE where:
        • ZIPFILE is a zipped shapefile in 3857
        • TYPE is on of the approved Focus Area types (see fishpass/project_settings.py FOCUS_AREA_TYPES)
        • example: dj import_focus_areas /usr/local/apps/marineplanner-core/apps/FishPass/layers/counties.zip County
          • County data is currently already included in loading the initial_data.json fixture
  8. Enable Anonymous User

    • TODO: decide if this is a valid use case, document if so.
  9. See steps below for installing OptiPass

Production Server Setup:

Bootstrap MarinePlanner

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install git
  4. mkdir /usr/local/apps
  5. sudo chgrp adm /usr/local/apps
  6. cd /usr/local/apps
  7. git clone https://github.com/Ecotrust/marineplanner-core.git

Install PostgreSQL/PostGIS and a few Dependencies

  1. cd /usr/local/apps/marineplanner-core/scripts/
  2. sudo chmod +x vagrant_provision0.sh
  3. sudo vagrant_provision0.sh bionic 3.7.0 10 #Ubuntu Bionic, GEOS 3.7.0, PostgreSQL 10

Installing FishPass

cd /usr/local/apps/marineplanner-core/apps
git clone https://github.com/Ecotrust/FishPass.git
cd FishPass/scripts
chmod +x configure_project.sh
cp configure_project.sh /usr/local/apps/marineplanner-core/scripts/configure_project.sh
cd /usr/local/apps/marineplanner-core/scripts/
./configure_project.sh fishpass
cd /usr/local/apps/marineplanner-core/apps/FishPass/
./vagrant_provision.sh marineplanner-core marineplanner marineplanner /usr/local/apps/marineplanner-core/apps/FishPass/fishpass
/usr/local/apps/marineplanner-core/apps/mp-accounts/scripts/vagrant_provision.sh marineplanner-core
/usr/local/apps/marineplanner-core/apps/mp-visualize/scripts/vagrant_provision.sh marineplanner-core
/usr/local/apps/marineplanner-core/apps/madrona-scenarios/scripts/vagrant_provision.sh marineplanner-core

Activate the virtualenvironment and install the dependencies:

Create Shortcut 'dj':

  1. sudo vim /etc/bash.bashrc
  2. Add the following to the bottom of the script:
    alias dj="/usr/local/apps/marineplanner-core/env/bin/python /usr/local/apps/marineplanner-core/marineplanner/manage.py"
    alias djrun="dj runserver 0:8000"
  3. now 'dj' will run 'manage.py' from wherever you are, without needing to activate your virtualenv
  4. now 'djrun' will spin up your django server on port 8000
    • DO NOT USE THIS AFTER EARLY TESTING
    • NEVER RUN THIS WITH SUDO OR AS ROOT
    • CLOSE PORT 8000 AFTER TESTING

Load Data:

  1. dj loaddata /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/fixtures/initial_setup.json

Install Optipass

  1. Get a copy of the OptiPass command line executable (c) Jesse O'Hanley
  2. Copy it to /usr/local/apps/marineplanner-core/apps/FishPass/OptiPass/
    • NOTE: This directory will be available when Ryan merges the OptiPass branch in
  3. sudo chmod +x /usr/local/apps/marineplanner-core/apps/FishPass/OptiPass/OptiPassMain.out
  4. sudo chmod 777 /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/media
  5. Install and Configure Instructions

Import FocusAreas

  1. dj import_focus_areas /usr/local/apps/marineplanner-core/apps/FishPass/layers/counties.zip County
    • you will have to change the file and supplied Focus Area type for other layers
    • See project_settings.py's FOCUS_AREA_TYPES for the other options

Install Requirements for Asynchronous Report Generation

sudo apt-get install rabbitmq-server
cd /usr/local/apps/marineplanner-core/marineplanner/marineplanner
ln -s /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/celery.py ./celery.py
cat /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/__init__.py >> __init__.py
Celery on boot

via http://docs.celeryproject.org/en/latest/userguide/daemonizing.html#usage-systemd

sudo su root
ln -s /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/deploy/celery.service /etc/systemd/system/celery.service
mkdir /etc/conf.d
ln -s /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/deploy/celery /etc/conf.d/celery
adduser celery
mkdir /var/log/celery
chown celery:celery /var/log/celery
systemctl start celery.service
sudo chown celery:www-data /usr/local/apps/marineplanner-core/apps/FishPass/fishpass/media/reports
sudo systemctl enable celery
sudo systemctl daemon-reload

NOTE: Double-check that you have media served by nginx (like static)

Install and Configure NGINX and UWSGI

  1. Copy configuration script:
    • ln -s /usr/local/apps/marineplanner-core/apps/FishPass/scripts/configure_production.sh /usr/local/apps/marineplanner-core/scripts/
    • cd /usr/local/apps/marineplanner-core/scripts/
    • sudo chmod +x configure_production.sh
    • ./configure_production.sh
sudo apt-get install nginx uwsgi uwsgi-plugin-python3 -y
pip install uwsgi

sudo cp /usr/local/apps/marineplanner-core/deployment/marineplanner_nginx.conf /etc/nginx/sites-available/marineplanner
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/marineplanner /etc/nginx/sites-enabled/marineplanner
sudo cp /usr/local/apps/marineplanner-core/deployment/uwsgi_params /etc/nginx/

sudo cp /usr/local/apps/marineplanner-core/deployment/emperor.ini /etc/uwsgi/
sudo ln -s /usr/local/apps/marineplanner-core/deployment/uwsgi.service /etc/systemd/system/
sudo ln -s /usr/local/apps/marineplanner-core/deployment/marineplanner.ini /etc/uwsgi/apps-enabled/

sudo chmod +x /usr/local/apps/marineplanner-core/deployment/restart_nginx.sh

sudo service uwsgi start
sudo service uwsgi restart
sudo cp /usr/local/apps/marineplanner-core/deployment/rc.local /etc/rc.local
Ubuntu 18.04 update

rc.local does not run by default on 18.04. You need to tell it to run on boot using systemd and systemctl. I recommend this tutorail

Install and Configure Email

sudo apt-get install postfix configuration:
Internet Site System mail name : enter the domain name you plan to use, i.e.: fishpass.psmfc.org

Then set Django settings to look something like this:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'FISHPass<fishpass@your.domain>'

Configure DNS for secure delivery (see internal documentation)

Configure ReCaptcha and Registration

NOTE: This does not seem required for the signup popup, only if user finds /account/

Install and Configure Munin

sudo apt-get install munin munin-node
sudo vim /etc/nginx/sites-enabled/marineplanner

Between the error_log line and the location /static line add:

location /munin/static/ {
        alias /etc/munin/static/;
}

location /munin {
        alias /var/cache/munin/www;
}

Then restart NGINX

sudo service nginx restart

Automatic (Unattended) Security Updates

From the document Using the "unattended-upgrades" package

Install the unattended-upgrades package if it isn't already installed:

sudo apt-get install unattended-upgrades

To enable it, do:

sudo dpkg-reconfigure --priority=low unattended-upgrades

(it's an interactive dialog) which will create /etc/apt/apt.conf.d/20auto-upgrades with the following contents:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

To have the server automatically reboot when necessary to install security upddates:

  1. install the package update-notifier-common
    sudo apt-get install update-notifier-common
  2. edit the file /etc/apt/apt.conf.d/50unattended-upgrades near the bottom you will find the line
    //Unattended-Upgrade::Automatic-Reboot "false";

    uncomment it and set value to true:

    Unattended-Upgrade::Automatic-Reboot "true";

    To tell the server what time is most safe to reboot (when needed), uncomment the line

    //Unattended-Upgrade::Automatic-Reboot-Time "02:00";

    And set the time to your desired restart time.

Read the source document for more details.