Buckzm
Buckzm

Reputation: 13

Creating MongoDB Start-up script

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..

Upvotes: 1

Views: 4966

Answers (2)

Buckzm
Buckzm

Reputation: 13

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.

Upvotes: 0

Nick
Nick

Reputation: 1554

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.

Upvotes: 2

Related Questions