3

I have a simple meteor app that I'm running on an Amazon EC2 server. Everything is working great. I start it manually with my user via meteor in the project directory.

However, what I would like is for this app to

  1. Run on boot
  2. Be immune to hangups

I try running it via nohup meteor &, but when I try to log out of the EC2 instance, I get the "You have running jobs" message. Continuing to log out stops the app.

How can I get the app to start on startup and stay up (unless it crashes for some reason)?

Charles
  • 50,943
  • 13
  • 104
  • 142
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405

3 Answers3

3

Install forever and use a start script.

$ npm install -g forever

I have several scripts for managing my production environment - the start script looks something like:

#!/bin/bash

forever stopall

export MAIL_URL=...
export MONGO_URL=...
export MONGO_OPLOG_URL=...
export PORT=3000
export ROOT_URL=...
forever start /home/ubuntu/apps/myapp/bundle/main.js

exit 0

Conveniently, it will also append to a log file in ~/.forever which will show any errors encountered while running your app. You can get the location of the log file and other stats about your app with:

$ forever list

To get your app to start on startup, you'd need to do something appropriate for your flavor of linux. You can maybe just put the start script in /etc/rc.local. For ubuntu see this question.

Also note you really should be bundling your app if using it in production. See this comparison for more details on the differences.

Community
  • 1
  • 1
David Weldon
  • 63,632
  • 11
  • 148
  • 146
  • Thanks, this helps a lot. I'm using Amazon Linux, not Ubuntu. I bundled it, but it won't start because it's missing `fibers`. I cd to `bundle/server` and run `npm install --nodedir=/usr/local/bin fibers`, but I get `gyp: /usr/local/bin/common.gypi not found`. Any ideas? – Explosion Pills Jan 30 '14 at 06:41
  • 1) see [this](http://stackoverflow.com/questions/13327088/meteor-bundle-fails-because-fibers-node-is-missing) question. 2) what version of node are you running? – David Weldon Jan 30 '14 at 06:48
  • It's recommended that you use the node versions specified in the [meteor history](https://github.com/meteor/meteor/blob/devel/History.md) for your particular release. Though, I suspect that may not be the issue here. Do a search for "node error common.gypi" and you will get several answers including [this one](http://stackoverflow.com/questions/21021884/node-expat-install-error-on-ubuntu-vm). – David Weldon Jan 30 '14 at 07:20
1

I am using upstart on Ubuntu server which you should be able to easily install on Amazon linux.

This is roughly my /etc/init/myapp.conf:

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

respawn
respawn limit 99 5

script
    export HOME="/home/deploy"
    export NODE_ENV="production"
    export MONGO_URL="mongodb://localhost:27017/myappdb"
    export ROOT_URL=http://localhost
    export MAIL_URL=smtp://localhost:25
    export METEOR_SETTINGS='{"somesetting":true}'

    cd /var/www/myapp/bundle/
    exec sudo -u deploy PORT=3000 /usr/bin/node main.js >> /var/log/node.log 2>&1
end script

I can then manually start and stop myapp like this:

sudo start myapp
sudo stop myapp
Tobias
  • 4,034
  • 1
  • 28
  • 35
0

I believe this package solves your problem: https://github.com/arunoda/meteor-up

which seems to use forever: https://github.com/nodejitsu/forever

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71