Webfaction is a great host for small websites, particularly if they use a fairly generic setup, but it can be a bit tricky if you have to start tinkering under the hood. Unfortunately getting MongoDB running at this time isn’t quite as simple as using one of the other database options. Webfaction has a useful guide for setting up MongoDB initially but it doesn’t really go into detail about managing the MongoDB process once it’s all setup.

One of the omissions from the guide is getting the process to auto-start if the server reboots, as being a shared server a lot of the standard Linux configurations for services are out-of-bounds. It can still be accomplished using a Crontab however and hooking it to a startup script.

Once MongoDB is all setup on Webfaction, add three scripts in the bin directory of the MongoDB app:

bin/start

NB you need to switch out ‘some port’ with port of the mongo app

bin/stop

bin/restart

Then edit your crontab to boot Mongo or a system reboot:

@reboot $HOME/webapps/mongo_db/bin/start

Voilà! Auto-rebooting on system reboot. It’s worth noting you may need to add an additional cron to reboot the process should it fail/crash.