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
Using Awk to Get a Specific String in Line
Parallel Processes: Appending Outputs to an Array in a Bash Script
How to Insert a Tab Character in Iterm
Udev-How to Get Value of a Child Device Attributes
Copying Local Git Config into Docker Container
Why Does Cat <<< $Var1 Lose Newlines
What Is Difference Between Sched_Batch and Sched_Other Scheduling
What's The Best Way to Move a Directory into Place in a Makefile Install
How to Enable Spell Checker in Google Colab (Colab Operates on Linux Os)
Sed: Remove Whole Words Containg a Character Class
Is The Program 'Yes' Used for Anything Significant
How to Continously Run a Unix Script in Background Without Using Crontab.
How to Get The Process Id of Command Executed in Bash Script
Gcc: Linked Libraries in /Usr/Local/Lib Are Not Found, But /Etc/Ld/So.Conf.D/Libc.Conf Lists It