2016-03-28 02:38:10 +00:00
|
|
|
#### Install passenger (e.g. Ubuntu Trusty like this:)
|
|
|
|
|
|
|
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \
|
|
|
|
--recv-keys 561F9B9CAC40B2F7
|
|
|
|
sudo apt-get install -y apt-transport-https ca-certificates
|
|
|
|
|
|
|
|
# Add APT repository
|
|
|
|
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
|
|
|
|
sudo apt-get update
|
|
|
|
|
|
|
|
# Install Passenger + Nginx (try apache if you would rather not change
|
|
|
|
# nginx)
|
|
|
|
sudo apt-get install -y nginx-extras passenger
|
|
|
|
|
|
|
|
#### Setup Postgres
|
|
|
|
|
|
|
|
sudo apt-get install postgresql-9.4 #specify version!!
|
|
|
|
sudo -u postgres psql
|
|
|
|
postgres=# CREATE USER metamaps WITH PASSWORD 'mycoolpassword' CREATEDB;
|
|
|
|
postgres=# CREATE DATABASE metamap002_production OWNER metamaps;
|
|
|
|
postgres=# \q
|
|
|
|
|
|
|
|
#### Install system-wide rvm:
|
|
|
|
|
|
|
|
sudo gpg --keyserver hkp://keys.gnupg.net \
|
|
|
|
--recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
|
|
|
|
\curl -sSL https://get.rvm.io | sudo bash -s stable
|
|
|
|
echo "gem: --no-ri --no-rdoc" | sudo tee -a /etc/gemrc
|
|
|
|
|
|
|
|
#### Create user and setup gemsets for that user
|
|
|
|
|
|
|
|
sudo adduser --disabled-password metamaps
|
|
|
|
sudo adduser metamaps rvm
|
|
|
|
|
|
|
|
#### Clone github repo and install gems
|
|
|
|
|
|
|
|
sudo su - metamaps
|
|
|
|
rvm user gemsets
|
2016-04-13 02:16:54 +00:00
|
|
|
git clone https://github.com/metamaps/metamaps \
|
2016-03-28 02:38:10 +00:00
|
|
|
--branch instance/mycoolinstance
|
2016-04-13 02:16:54 +00:00
|
|
|
rvm install $(cat metamaps/.ruby-version) #ensure ruby is installed
|
|
|
|
cd metamaps
|
2016-03-28 02:38:10 +00:00
|
|
|
gem install bundle
|
|
|
|
bundle install
|
|
|
|
|
|
|
|
#### Connect rails database
|
|
|
|
|
2016-04-13 02:16:54 +00:00
|
|
|
Run this in the metamaps directory, still as metamaps:
|
2016-03-28 02:38:10 +00:00
|
|
|
|
2016-06-20 00:31:32 +00:00
|
|
|
# fill in DB_* values, and realtime server at least. Change the
|
|
|
|
# SECRET_KEY_BASE to something new. Ctrl+X to save/exit from nano.
|
2016-03-28 02:38:10 +00:00
|
|
|
cp .example-env .env
|
2016-06-20 00:31:32 +00:00
|
|
|
nano .env
|
|
|
|
|
|
|
|
# Set up environment variables in your current session
|
|
|
|
source .env
|
2016-03-28 02:38:10 +00:00
|
|
|
export RAILS_ENV=production
|
2016-08-01 19:59:53 +00:00
|
|
|
export NODE_ENV=production
|
2016-06-20 00:31:32 +00:00
|
|
|
|
|
|
|
# create, load schema, seed
|
|
|
|
rake db:setup
|
2016-03-28 02:38:10 +00:00
|
|
|
|
2016-08-03 14:37:02 +00:00
|
|
|
#### Install node & ES6 modules
|
2016-08-01 19:59:53 +00:00
|
|
|
|
|
|
|
sudo aptitude install nodejs npm
|
|
|
|
sudo ln -s /usr/bin/nodejs /usr/bin/node
|
|
|
|
npm install
|
|
|
|
npm run build
|
|
|
|
|
|
|
|
#### Nginx and SSL
|
|
|
|
|
2016-08-04 02:51:36 +00:00
|
|
|
Now set up nginx - config stored on Linode, including relevant environment variables.
|
2016-03-28 02:38:10 +00:00
|
|
|
|
|
|
|
Get an SSL certificate and encrypt it for the realtime video.
|
|
|
|
|
|
|
|
#### And finally
|
|
|
|
|
2016-04-13 02:16:54 +00:00
|
|
|
passenger-config restart-app /home/metamaps/metamaps
|
2016-03-28 02:38:10 +00:00
|
|
|
|
2016-06-20 00:31:32 +00:00
|
|
|
If this command fails, it may be helpful for debugging to run a test
|
|
|
|
server to see what problems show up:
|
2016-03-28 02:38:10 +00:00
|
|
|
|
|
|
|
RAILS_ENV=production rails server
|
|
|
|
|
|
|
|
#### Realtime server:
|
|
|
|
|
|
|
|
sudo npm install -g forever
|
2016-04-13 02:16:54 +00:00
|
|
|
(crontab -u metamaps -l 2>/dev/null; echo "@reboot $(which forever) --append -l /home/metamaps/logs/forever.realtime.log start /home/metamaps/metamaps/realtime/realtime-server.js") | crontab -u metamaps -
|
2016-03-28 02:38:10 +00:00
|
|
|
|
2016-04-13 02:16:54 +00:00
|
|
|
cd /home/metamaps/metamaps/realtime
|
2016-03-28 02:38:10 +00:00
|
|
|
npm install
|
|
|
|
mkdir -p /home/metamaps/logs
|
|
|
|
forever --append -l /home/metamaps/logs/forever.realtime.log \
|
2016-04-13 02:16:54 +00:00
|
|
|
start /home/metamaps/metamaps/realtime/realtime-server.js
|
2016-03-28 02:38:10 +00:00
|
|
|
|
|
|
|
#### Upstart service for delayed_worker:
|
|
|
|
|
|
|
|
Put the following code into `/etc/init/metamaps_delayed_worker.conf`:
|
|
|
|
|
|
|
|
description "Delayed Jobs Worker for Metamaps"
|
|
|
|
|
|
|
|
start on runlevel [2345]
|
|
|
|
stop on runlevel [!2345]
|
|
|
|
|
|
|
|
setuid metamaps
|
|
|
|
setgid metamaps
|
2016-04-13 02:16:54 +00:00
|
|
|
chdir /home/metamaps/metamaps
|
2016-03-28 02:38:10 +00:00
|
|
|
|
|
|
|
env HOME=/home/metamaps
|
2016-08-01 00:33:45 +00:00
|
|
|
env PATH="/usr/local/rvm/gems/ruby-2.3.0@metamaps/bin:/usr/local/rvm/gems/ruby-2.3.0@global/bin:/usr/local/rvm/rubies/ruby-2.3.0/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/bin:/bin"
|
|
|
|
env GEM_PATH="/usr/local/rvm/gems/ruby-2.3.0@metamaps:/usr/local/rvm/gems/ruby-2.3.0@global"
|
2016-03-28 02:38:10 +00:00
|
|
|
env RAILS_ENV="production"
|
|
|
|
|
|
|
|
respawn
|
|
|
|
respawn limit 3 30
|
|
|
|
|
|
|
|
exec bundle exec rake jobs:work
|
|
|
|
|
|
|
|
Then start the service and check the last ten lines of the log file to make sure it's running OK:
|
|
|
|
|
|
|
|
sudo service metamaps_delayed_job start
|
|
|
|
tail /var/log/upstart/metamaps_delayed_job.log
|