Run Meteor as a Daemon Process

Run Meteor as a Daemon process

Meteor Up creates a daemon with these features:

  • Auto-Restart if the app crashed (using forever)

  • Auto-Start after the server reboot (using upstart)

How to run meteor in the background forever

I use Forever in my Meteor app.

How to run meteor on startup on Ubuntu server

You should use Ubuntu way, which is Upstart:

http://upstart.ubuntu.com/
http://manpages.ubuntu.com/manpages/lucid/man5/init.5.html

How to define daemon job:

http://newcome.wordpress.com/2012/02/26/running-programs-as-linux-daemons-using-upstart/

Hope it helps :)

Your upstart file would be more or less:

# meteorjs - meteorjs job file

description "MeteorJS"
author "Igor S"

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Run before process
pre-start script
cd PATH_TO_METEOR_APP
echo ""
end script

# Start the process
exec meteor run -p 80 --help -- production

How does one start a node.js server as a daemon process?

Forever is answer to your question.

Install

$ curl https://npmjs.org/install.sh | sh
$ npm install forever
# Or to install as a terminal command everywhere:
$ npm install -g forever

Usage

Using Forever from the command line

$ forever start server.js

Using an instance of Forever from Node.js

var forever = require('forever');

var child = new forever.Forever('your-filename.js', {
max: 3,
silent: true,
args: []
});

child.on('exit', this.callback);
child.start();

Keep meteor running on amazon EC2

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.



Related Topics



Leave a reply



Submit