1

I have been struggling on creating mongodb start-up script.

I have this file here "script.js" that contain my scripts that i want to execute every-time the server boot.

My script file is under "/opt/temp/script.js"

db.getCollectionNames().forEach(function(collection) {
  print(collection);
});

Which command should I write to execute this file every time after the sever restarted ? Where to put that command ? Please help me

Thanks you..

Buckzm
  • 13
  • 1
  • 5

2 Answers2

2

What version of Linux are you using, what version of MongoDB have you installed, and how did you install it?

If, for example, you installed Mongodb on Ubuntu as per the MongoDB Docs you should have a start up script in /etc/init.d/mongod which will auto-start MongoD on boot.

If you have installed, say, a release candidate in a non standard location, I found these scripts to be fairly good and very alterable.

Using this script will NOT guarantee mongod starting on boot. You'll need to use sysv-rc-conf to set the run-levels correctly, like the apache2 line in the image linked.

Nick
  • 1,554
  • 1
  • 10
  • 27
  • Hi Nick Thanks for response I'm using SUSE Linux Enterprise Server 11, I think my question was not clear enough I have mongodb running on Start-up fine what i want to is I want to be able to run some mongo commands saved in the "script.js" file I mentioned above on the start-up ? I hope this is clear enough – Buckzm Feb 25 '13 at 08:02
0

Hi I managed to get it working I created Script.jsfile with my mongoDb commands and place it at /op/myscripts. Then on the mongodb-confI included the command to execute my script once mongodb is started command mongo /opt/myscripts/script.js.

Buckzm
  • 13
  • 1
  • 5