First off, props to robmoggach for creating a script that attempts to do the job, however I'm working on a Meteor app that requires Mongo and found that the script wasn't setting everything up to completion. Here's an attempt to catalog all the steps I performed, in the hopes it might save someone a bit of headache someday:
1. Use the WebFaction web dashboard to provision your app directories
- Log in, go to Domains/Websites > Applications, click to add a new application
- Name this one for your Meteor app (for the rest of this doc let's use myapp as your moniker), e.g. myappmeteor
- Change the app category to Custom, type to Custom websockets app (listening on port), check to open a port in the firewall
- Save and note the port number you get (let's say it's 20000, you'll need this later)
- Click to add a second application
- Name this one for the Mongo instance backing your app, e.g. myappmongo
- Change the app category to Custom, type to Custom app (listening on port), this one doesn't need a public forwarded port
- Save and note the port number you get (let's say it's 30000 for the DB)
- Switch to Domains/Websites > Websites, add a new website using the IP of the server where you got port 20000 assigned
- Name it as you wish, e.g. myapp, attach it to your domain name of choice (let's say it's myapp.com)
- For the Contents, click Add an application > Reuse an existing application, pick myappmeteor, save
- First, do you see
~/webapps/myappmeteor
and~/webapps/myappmongo
? High five! - Now your task is to install Node (at least v0.10.40 as of this writing), MongoDB, Meteor, and optionally Forever.js for your user
- This part works really well in that script I mentioned earlier, you should probably just install it and run
wfmtr bootstrap
to get them installed (although beware, at the moment, the script installs Node v0.10.36) - Otherwise, install them yourself such that you have
node
,mongod
, andmeteor
in your~/bin
directory - Also for Forever.js you can just run
npm install -g forever
once you have Node set up
- If you installed Mongo successfully, in your SSH shell try:
PIDFILE=~/webapps/myappmongo/mongod.pid ~/bin/mongod --fork --noauth --dbpath ~/webapps/myappmongo/data --port 30000 --logpath ~/webapps/myappmongo/mongod.log
(replacing 30000 with the correct Mongo port from your custom app in step 1) - Now you should be able to
mongo localhost:30000
and see the Mongo shell working. Great, you can close it now - Make sure the Mongo daemon is still active (use
ps -A
and look for mongod) before proceeding
- Here you have a few options. You can
meteor build
the server on your dev machine and upload the bundle, or you can build from source on WebFaction's service and drop the bundle in that way - I'll walk through the latter - Suppose your source is on GitHub, then you can
cd ~/webapps/myappmeteor
andgit clone https://github.com/me/myapp.git
- Now
cd myapp
andmeteor build --directory ~/webapps/myappmeteor
(note that if you're using Cordova in your app, you should firstmeteor remove-platform ios
andmeteor remove-platform android
so that you only build the server, having an iOS project in particular will cause the build to fail) cd ../bundle/programs/server
andnpm install
or else you'll get mysterious errors about fibers not being present- Optionally test it at this point:
MONGO_URL='mongodb://localhost:30000/myapp' ROOT_URL='http://myapp.com' PORT=20000 DDP_DEFAULT_CONNECTION_URL='http://myapp.com:20000' node ~/webapps/myappmeteor/bundle/main.js
again replacing the port numbers, app names etc. - At this point Node should've taken over your terminal. Go use your browser and hit up http://myapp.com - your app working now? Another high five for you!
- Back to SSH, you can Ctrl+C to stop Node now (and you should get a Bad Gateway error at this point if you were to refresh your browser on the page)
- The last bit is to make Node run forever and restart the Mongo daemon should it get killed at some point
touch ~/bin/startmyapp.sh
andchmod 750 ~/bin/startmyapp.sh
andnano ~/bin/startmyapp.sh
or whatever your favorite editor is to create this script:
#!/bin/sh
if [ $(ps aux | grep $USER | grep mongod | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
export PIDFILE='~/webapps/myappmongo/mongod.pid'
~/bin/mongod --fork --noauth --dbpath ~/webapps/myappmongo/data --port 30000 --logpath ~/webapps/myappmongo/mongod.log
fi
if [ $(ps aux | grep $USER | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
export MONGO_URL='mongodb://localhost:30000/myapp'
export ROOT_URL='http://myapp.com'
export PORT=20000
export DDP_DEFAULT_CONNECTION_URL='http://myapp.com:20000'
forever start --pidfile ~/webapps/myappmeteor/forever.pid --append -l ~/webapps/myappmeteor/forever.log -o ~/webapps/myappmeteor/out.log -e ~/webapps/myappmeteor/err.log ~/webapps/myappmeteor/bundle/main.js
fi
- Save and exit Nano
- Run your script once now (just type
~/bin/startmyapp.sh
) and refresh your browser, make sure all is well - Lastly
EDITOR=nano crontab -e
and add a new line0 0 * * * ~/bin/startmyapp.sh
, save and exit
Someone want to go finish the rest of that script so that we can have this fully automated?
robmoggach's handy script, why you need to npm install your bundle first, why you should set the DDP URL by hand, WebFaction forum threads on Node + Websocket and Node + Mongo, cron + Forever.
Sadly, don't expect this setup to work with the Cordova version of your app (as of Meteor 1.2). You'll just end up banging your head against the wall. Hopefully Meteor 1.3 will make it work.