Self-hosted Meteor Deploy script

Most of the Meteor apps I write are deployed on our local intranet, and seeing how Galaxy as not been released, I've spent a bit of work on deployment tooling.

This is the current version of the deployment script we use, which may be of use to someone.

The server should:

  1. Have a working linux install.
  2. Let you log on via SSH, preferably passwordless since there's a few round-trips.
  3. Have nvm installed.
  4. Have pm2 installed.

And with an application there is some initial setup, the first time you publish an app:

  1. Update the configuration settings at the top of the script.
  2. Create a JSON configuration block for pm2. This is where you'd pass the environment variables (mongo url, port, smtp settings) and meteor settings. There's an example in the embedded gist.
  3. Create the deployment folder, the deployment backup folder.
  4. Manually start the process the first time, using something like pm2 start pm2-testapp.json

Afterwards the deployment script will handle restarts.