Reputation: 4171
I want to get programmatically the path of configuration file which mongodb loaded. Is it possible to get this by running a command or something?
Upvotes: 18
Views: 23313
Reputation: 637
This is just to complement a bit the other answers. Another way, in Linux is to first run ps and check whether there is a configuration file passed-in.
$ ps axww | grep mongod | grep -v grep
14886 ? Sl 0:00 /usr/bin/mongod -f /etc/mongod.conf
The case above is for mongod running in Fedora 32, but it would work for any Linux where mongo was started by systemd, upstart or whichever process manager.
The config file may NOT be mentioned in the command line arguments, like it happens to be the case when you start manually mongod from the command line or in the mongo docker container image:
$ docker run --name some-mongo -d mongo:latest
$ docker exec -t some-mongo bash -c "ps axww | grep mongod | grep -v grep"
1 ? Ssl 0:00 mongod --bind_ip_all
In these cases mongo starts with default values.
For related information, see this SO question or the reference mongo documentation.
Upvotes: 1
Reputation: 12233
On ubuntu 16 if you run systemctl status mongodb
It will show you the following. At the bottom, you can see --config /etc/mongod.conf
, which looks like is the location of my loaded config file
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2016-08-09 14:33:03 UTC; 3s ago
Main PID: 6674 (mongod)
Tasks: 21
Memory: 40.1M
CPU: 230ms
CGroup: /system.slice/mongodb.service
└─6674 /usr/bin/mongod --quiet --config /etc/mongod.conf
Upvotes: 10
Reputation: 12240
In mongo shell you can run a getCmdLineOpts command on admin
database which will give you the command line options used to start the mongod or mongos:
db.runCommand({getCmdLineOpts:1})
{
"argv" : [
"/usr/bin/mongod",
"--config",
"/etc/mongodb.conf"
],
"parsed" : {
"config" : "/etc/mongodb.conf",
"net" : {
"port" : 27017
},
"storage" : {
"dbPath" : "/var/lib/mongodb"
},
"systemLog" : {
"destination" : "file",
"logAppend" : true,
"path" : "/var/log/mongodb/mongodb.log"
}
},
"ok" : 1
}
Upvotes: 28