MathML Cloud Server Admin

Skip to end of metadata
Go to start of metadata

URLs

Start and Stop the API

Both live and staging VMs have the same admin user, mmlc. See Meghan or John for credentials.

The API runtime is managed by pm2, a Node tool for keeping a Node instance running.

ssh -l mmlc mathml-cloud.cloudapp.net -p 22
cd mathml-cloud
sudo pm2 list # get a list of processes running
sudo pm2 stop 0 # stop process 0, MMLC
# Pass along environment settings that are set for the mmlc user
sudo SECRET_TOKEN=${SECRET_TOKEN} \
MONGO_URL=$MONGO_URL \
NODE_ENV=$NODE_ENV \
SMTP_SASL_USER=$SMTP_SASL_USER \
SMTP_SASL_PASSWORD=$SMTP_SASL_PASSWORD \
pm2 start app.js # starts MMLC

Note: The SECRET_TOKEN environment variable is needed for the Github commit hook, described below.

Create a server VM

The Vagrant file is configured to provision VMs on either Azure or VirtualBox. To provision a server for local development on VirtualBox:

cd path/to/your/mathml-cloud
vagrant up --provider=virtualbox

To provision a server on Azure:

vagrant plugin install vagrant-azure
vagrant box add azure https://github.com/msopentech/vagrant-azure/raw/master/dummy.box
vagrant up --provider=azure

You will need the keys directory and a file named secrets.yaml in the app's root directory, ex:

subscription_id: 'xxxxxxx'
mgmt_certificate: 'keys/mgmt-key/cert.pem'
username: 'mmlc'
password: 'xxxxxx'
ssh_private_key_file: 'keys/ssh-key/myPrivateKey.key'
ssh_certificate_file: 'keys/ssh-key/myCert.cer'

Database changes

Sails will not do any database migrations when running as production. Sails.js, http://sailsjs.org/#/documentation/concepts/Deployment, recommends using 1 of 2 approaches for database migrations:

1. Create the database on the server and then run your sails app with migrate:alter locally, but configured to use the production server as your db. This will automatically set things up.
2. In case you can't connect to the server remotely, you'll simply dump your local schema and import it into the database server.

Up to this point, all production database migrations for mathmlcloud.org have been performed by cloning the release branch, updating config/connections.js with the url to production's MongoLab database, and running sails lift in your local checkout's home directory, ex ~/boss/mathmlcloud-v5.1.5

Deploy code to staging

A Github hook has been configured to deploy to staging on all pushes to the master branch. Typical workflow:

  • Make changes locally and push to your fork of mmlc-api or mmlc-app.
  • On github, create a pull request.
  • Have a fellow developer do a code reading of your changes and merge the pull request into benetech's master repository.
  • Once the request has been merged, a request will be sent to staging to update all code and restart the server.

Each of the repositories has a hook defined similarly:

The hook is implemented within the API in the api/controllers/GitHookController.js file.

Deploy code to live

  • ssh to the server
  • checkout the latest releases for the app and for the api. The api is installed at ~/mathml-cloud and the app is installed at ~/mathml-cloud/assets.
  • install any new node packages
  • restart the server
ssh -l mmlc mathml-cloud.cloudapp.net -p 22
cd mathml-cloud
sudo git fetch #You should see the release branch listed here
sudo git checkout {yourBranch}
sudo npm -y install --no-bin-links
cd assets
sudo git fetch
sudo git checkout {yourBranch}
cd ..
sudo pm2 list # get a list of processes running
sudo pm2 stop 0 # stop process 0, MMLC
sudo SECRET_TOKEN=${SECRET_TOKEN} \
MONGO_URL=$MONGO_URL \
NODE_ENV=$NODE_ENV \
SMTP_SASL_USER=$SMTP_SASL_USER \
SMTP_SASL_PASSWORD=$SMTP_SASL_PASSWORD \
pm2 start app.js # starts MMLC

Starting the app as production will not perform any database migrations so they will have to be done locally (See Database changes above).

Troubleshooting

Steps to follow if website is down :

  • Try restarting from Azure
  • Run command to check if process is running by:
ssh -l mmlc mathml-cloud.cloudapp.net -p 22
cd mathml-cloud
sudo pm2 list

Should see one process running. If not , need to restart server by running the following command :

sudo pm2 stop 0 # stop process 0, MMLC (precautionary)
sudo SECRET_TOKEN=${SECRET_TOKEN} \
MONGO_URL=$MONGO_URL \
NODE_ENV=$NODE_ENV \
SMTP_SASL_USER=$SMTP_SASL_USER \
SMTP_SASL_PASSWORD=$SMTP_SASL_PASSWORD \
pm2 start app.js # starts MMLC
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.