Skip to content
Jia Huang edited this page Jun 12, 2014 · 12 revisions

#Portal Portal relies on several things:

  1. Discourse needs to have embedding set up so that comments can show up
  2. Tessel Oauth is used for all of the sign in, so those have to be pointed properly.

Portal runs on Digital Ocean. The stack is:

  • Nginx
  • Portal
  • Postgres
  • Redis

Bringing up a new box

  1. Bring up a new DO box (512MB works)

  2. Run the following

    apt-get update;
    apt-get install nodejs nodejs-legacy npm nginx postgresql postgresql-contrib redis-server
    

The postgres user can use psql to access the postgres database. Launch the postgres console via

sudo -u postgres psql -U postgres
  1. Set up Nginx

    1. make a config file for the app vi /etc/nginx/sites-available/portal
    upstream portal {
     server 127.0.0.1:3000;
    }
    
    server {
     listen 0.0.0.0:80;
    
         access_log /var/log/nginx/portal.log;
         # Make site accessible from http://localhost/
         server_name portal.tessel.io; # swap out with server name
    
         location / {
                 proxy_pass http://portal/;
                 proxy_redirect off;
         }
    
    }
    
    1. symlink over to sites-enabled ln -s /etc/nginx/sites-available/portal /etc/nginx/sites-enabled/portal
    2. restart nginx sudo /etc/init.d/nginx restart
  2. Set up Redis. Default Redis port is 6379.

  3. Set up backups

  4. Make these directories

    mkdir /opt/backups;
    mkdir /opt/scripts;
    mkdir /opt/logs;
    
  5. put this backup_postgres.sh script in /opt/scripts

    #!/bin/bash
    
    DATE=$(date +"%m-%d-%y")
    echo "Starting backup of $1 on $DATE"
    
    pg_dump -U postgres $1 > /opt/backups/$1-$DATE.sql
    
  6. Set up a cronjob. The backup_postgres script can only be run as the postgres user and not root, so either switch to the postgres user or add backup to the postgres cronjob. Right now we're going to add it to the postgres cron job.

`su postgres; crontab -e;`

 Now add the following

 ```
 0 3 * * * /opt/scripts/backup_postgres.sh portal > /opt/logs/backup_postgres.log 2>&1
 ```

**TODO: UPLOAD TO S3**

*** make sure permissions are properly set on all files not accessed by root ***
  1. Clone down the repo cd /opt/apps; git clone https://github.com/tessel/portal.git

  2. Fill out the config envs to .env or copy them over from another server

  3. Run the db migrations

    1. make the proper users/databases in postgres. switch to the postgres user su postgres;' then psql -U postgres`
    2. Now alter the database:
    create user portal;
    create database tesselportal owner portal;
    alter user portal with password 'testpw';
    
    1. exit out of psql and run the db migrations with make migrate.
  4. Set up Nginx, Postgres, Redis, and the node app to boot on startup. (I think that the nginx, postgres, and redis setup already covers this part)

  5. Run the node app. Forever.

    npm install -g forever
    

    make a file called /opt/scripts/start_app.sh

    #!/bin/bash
    
    cd /opt/app/portal;
    forever start app.js;
    

    Then add this to /etc/rc.local

    sh /opt/scripts/start_app.sh > /opt/logs/start_app.log 2>&1
    

Now hit the server and you should see portal.

Clone this wiki locally