Skip to content
Jia Huang edited this page Jun 27, 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_redirect off;
                 //proxy_set_header   X-Real-IP            $remote_addr;
    

           //proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;            //proxy_set_header   X-Forwarded-Proto $scheme;            proxy_set_header   Host                   $http_host; // set the host name here            proxy_set_header   X-NginX-Proxy    true;            proxy_set_header   Connection ""; proxy_pass http://portal/; }

}

2. symlink over to sites-enabled `ln -s /etc/nginx/sites-available/portal /etc/nginx/sites-enabled/portal`
3. restart nginx `sudo /etc/init.d/nginx restart`


4. [Set up Redis](http://redis.io/topics/quickstart). Default Redis port is 6379.

4. Set up backups
1. Make these directories
  ```
  mkdir /opt/backups;
  mkdir /opt/scripts;
  mkdir /opt/logs;
  ```

2. 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
  ```
2. 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
  ```

 *** make sure permissions are properly set on all files not accessed by root ***

5. Clone down the repo `cd /opt/apps; git clone https://github.com/tessel/portal.git`
 
6. Fill out the config envs to `.env` or copy them over from another server

7. 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';
  ```
3. exit out of `psql` and run the db migrations with `make migrate`.
8. 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)

9. [Supervisor that up](https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps).

1.  `vi /etc/supervisor/conf.d/portal.conf`

  ```
  [program:portal]
  command=/opt/apps/portal/startup.sh
  autostart=true
  autorestart=true
  stderr_logfile=/var/log/portal.err.log
  stdout_logfile=/var/log/portal.out.log
  ```
2. `supervisorctl reread; supervisorctl update`
3. If you need to restart/start/stop run 
  
  ```
  >> supervisorctl
  supervisor> stop portal
  supervisor> start portal
  supervisor> restart portal
  ``` 
10. Restart nginx `sudo /etc/init.d/nginx restart`
Now hit the server and you should see portal.
Clone this wiki locally