7

I learn meteorjs and I have a small remote VPS.

I want:

  1. Set auto pulling from git repository my meteor project.
  2. Put script into auto start which run my meteor project as service.

For example

meteor run -p 80 -- production

My server is Ubuntu 12.04

Tarang
  • 75,157
  • 39
  • 215
  • 276
Ihor Shubin
  • 10,628
  • 3
  • 25
  • 33

3 Answers3

13

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
gor
  • 11,498
  • 5
  • 36
  • 42
bluszcz
  • 4,054
  • 4
  • 33
  • 52
  • how to run meteorite at startup with Mac OSX ? – crapthings Mar 27 '13 at 11:49
  • When I run that i get "'/vagrant/.meteor' exists, but '/vagrant/.meteor/meteor' is not executable. Remove it and try again." – Mike Graf Jun 13 '13 at 23:42
  • @MikeGraf, even better - I am trying to derive a mrt upstart from this example, but cannot seem to get it working.. any chance you could share some tips? It's really just the `exec` stanza that I can't figure out.. – stevemanuel Jul 20 '13 at 01:44
  • We had to `cwd` before executing `meteor` (so that we were in the project directory), probably have to do that with `mrt. – Mike Graf Jul 22 '13 at 17:39
  • 4
    Sure you want to run the server as root? – netAction Dec 20 '13 at 17:38
  • For me, the stop process does not actually work properly, it remains running so I added a post script to this: post-stop script # clean up echo "Shutting down meteor & cleaning up" pkill -9 -f meteor rm -f /var/web/meteor-ratings-app/.meteor/local/db/mongod.lock end script – radtek Oct 19 '14 at 01:40
4

Here is what I do:

description "meteor app server"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
pre-start script
   set -e
   rm -f /path/to/your/app/.meteor/local/db/mongod.lock
end script
exec /bin/su - ec2-user -c '/path/to/your/app/meteor_server.sh'
post-stop script
    pkill -f meteor
end script

The meteor_server.sh script contains:

cd /path/to/your/app/; meteor run -p 3000 --production

Make sure to chmod +x the meteor_server.sh script and change the path to your app in the 3 locations. The script also kills all meteor tasks when it is stopped so it works for running a single meteor app only on your server. I got a meteor app running quickly this way using nginx but node seems to consume a lot of memory.

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
radtek
  • 34,210
  • 11
  • 144
  • 111
1

This is my meteorjs.conf file - works fine. I had all described issues before, but this variant fix them. Hope it helps somebody :)

All EXPORT variables I got by printenv

# meteorjs - meteorjs job file

description "MeteorJS"
author "Alex Babichev"

# 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

chdir /home/dev/www/test

script

export MONGO_URL=mongodb://localhost:27017/meteor
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PWD=/home/sputnik
export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
export HOME=/home/sputnik

echo "---- start ----"
cd /home/dev/www/test
exec mrt

end script
  • Didn't pass the mongo url and changed last line for : `exec meteor -p domain.com:8080` also had to `chmod +x /etc/init/meteorjs.conf` and it works great :) Thx – Guidouil Jun 16 '14 at 15:22
  • `env HOME=/home/sputnik` if you don't like script in your script. – Cees Timmerman Dec 30 '15 at 10:17