meteor

Deployment with Upstart

Upstart Service

This deployment guide assumes you’re using an Ubuntu server, and are either self-hosting or using an Infrastructure as a Service (IaaS) provider, such as Amazon Web Services or Rackspace. Your Ubuntu server needs to be running a daemon for launching other apps, for which we recommend the Upstart service. You can find more about Upstart with the following links:

Upstart - Getting Started
Getting Started with Upstart Scripts on Ubuntu
UbuntuBootupHowTo
Upstart Intro, Cookbook, and Best Practices
Run NodeJS As a Service on Ubuntu Karmic

Copying Files To Your Server Then Build

One favored approach to deploying to a server is to use Git or GitHub. This basically involves logging into your server, moving to the directory you want to run your app from, then cloning your files directly from GitHub. You then build your app on the server. This approach ensures that platform specific files get built correctly, but requires that Meteor is installed on the server (500+ MB), and can result in slightly different builds wind up in production if your servers are slightly different.

cd /var/www
sudo git clone https://github.com/myaccount/myapp.git
cd /var/www/myapp
meteor build --directory ../myapp-production
sudo service myapp restart

Bundle Then Copy To Server

Alternatively, you may want to build your application, and then deploy it..

cd myapp
meteor build --directory ../output
cd ..
scp output -r username@destination_host:/var/www/myapp-production

Writing Your Upstart Script

You’ll need an upstart script in your /etc/init/ directory. Name it with your app’s name, ending in .conf, such as /etc/init/myapp.conf. The basic upstart script looks something like this:

## /etc/init/myapp.conf
description "myapp.mydomain.com"
author      "somebody@gmail.com"

# Automatically Run on Startup
start on started mountall
stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    export HOME="/root"
    export MONGO_URL='mongodb://myapp.compose.io:27017/meteor'
    export ROOT_URL='https://myapp.mydomain.com'
    export PORT='80'

    exec /usr/local/bin/node /var/www/myapp/main.js >> /var/log/myapp.log 2>&1
end script

Upstart Script For Replica Sets

If you’re running a replica set or have a need to shard your database, you’ll want an upstart script that looks something like this:

# /etc/init/myapp.conf
description "myapp.mydomain.com"
author      "somebody@gmail.com"

# used to be: start on startup
# until we found some mounts weren't ready yet while booting:
start on started mountall
stop on shutdown

# Automatically Respawn:
respawn
respawn limit 99 5

script
    # upstart likes the $HOME variable to be specified
    export HOME="/root"

    # our example assumes you're using a replica set and/or oplog integreation
    export MONGO_URL='mongodb://mongo-a,mongo-b,mongo-c:27017/?replicaSet=meteor'

    # root_url and port are the other two important environment variables to set
    export ROOT_URL='https://myapp.mydomain.com'
    export PORT='80'

    exec /usr/local/bin/node /var/www/production/main.js >> /var/log/node.log 2>&1
end script

Running Your Upstart Script

Finally, you’ll need to start the Upstart daemon, and initialize your app as a service.

sudo service myapp start

Setting up a Server to Host Multiple Meteor Apps

https://www.phusionpassenger.com/
https://github.com/phusion/passenger
https://github.com/phusion/passenger/wiki/Phusion-Passenger:-Meteor-tutorial#wiki-installing


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow