Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have to start my MongoDB server every time the system restarts. How do I configure it to start with my OS? I am on Ubuntu 11.04.

share|improve this question
    
I wonder why noone recommends using upstart here. –  Tom Mar 9 '12 at 17:37
add comment

migrated from stackoverflow.com Sep 15 '11 at 7:08

This question came from our site for professional and enthusiast programmers.

5 Answers

If you install MongoDB using the Advanced Packaging Tool (apt) then it'll configure your startup scripts to automatically run Mongo when the system boots.

The steps are as follows, first configure apt to be able to download the Mongo package:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo nano /etc/apt/sources.list

Add this line to sources.list then save:

deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen

Then download and install Mongo with the apt-get utility:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mongodb-10gen

If you want to make any changes to config, edit your mongodb.conf and restart:

sudo nano /etc/mongodb.conf
sudo service mongodb restart
share|improve this answer
2  
If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf. –  kynan Dec 5 '12 at 12:08
add comment

Controlling all the init.d service links should be done with the update-rc.d tool

i.e. to turn on the mongod daemon in the default runlevels (i.e. turn it on at boot):

update-rc.d mongodb defaults

See https://help.ubuntu.com/community/UbuntuBootupHowto for more information. This link tells you everything you want to know about how to set programs at boot.

share|improve this answer
1  
The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf. –  kynan Dec 5 '12 at 12:04
add comment

chkconfig --levels 235 mongod on?

where mongodb is the name of your service

share|improve this answer
1  
The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead. –  kynan Dec 5 '12 at 12:16
add comment

I have consistently used this post as a starting point to get a new sharding rig up and running. It includes a section on configuring upstart that I've also used.

http://joslynesser.com/blog/archives/2010/09/28/mongodb-sharding-guide-server-setup-on-ubuntu-ec2/

share|improve this answer
    
Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart. –  rigved Dec 23 '11 at 6:39
add comment

If you install MongoDB with apt-get as described in the MongoDB Ubuntu installation guide, it will come with a basic startup script and config file. (use of a config file is highly recommended)

You can also take a look here for an old post that links to an init.d script.

In either case, the basic premise is that you're setting up a service and then configuring to start-stop with the computer. This is pretty common technique for servers, there are lots of tutorials around for doing exactly this.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.