-
Notifications
You must be signed in to change notification settings - Fork 0
Portal
#Portal Portal relies on several things:
- Discourse needs to have embedding set up so that comments can show up
- 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
-
Bring up a new DO box (512MB works)
-
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
-
Set up Nginx
- 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;
- make a config file for the app
//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
```
**TODO: UPLOAD TO S3**
*** 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. 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.