There is an issue with RHEL9 starting the mongod deamon with systemctl start mongod.
Two examples of this issue are:
- Moving the database location
- Changing Listing port
Example 1. Database location
storage:
dbPath: /var/lib/mongo
network interfaces
net:
port: 27017
systemctl start mongod – this works just fine as the defaults.
Now lets move the DB directory to \var\lib\mongo1 – SAME mount point, SAME permissions
[root@REDHAT-3212 firewalld]# ll /var/lib | grep mongo
drwxr-xr-x. 5 mongod mongod 4096 Apr 17 15:27 mongo
drwxr-xr-x. 2 mongod mongod 6 Apr 17 15:27 mongo1
storage:
dbPath: /var/lib/mongo1
systemctl start mongod –
FAILS with permission issue:
{“t”:{“$date”:“2024-04-17T15:30:16.960-05:00”},“s”:“E”, “c”:“WT”, “id”:22435, “ctx”:“initandlisten”,“msg”:“WiredTiger error message”,“attr”:{“error”:13,“message”:“[1713385816
:960404][159449:0x7f26d62a0b80], wiredtiger_open: [WT_VERB_DEFAULT][ERROR]: __posix_open_file, 815: /var/lib/mongo1/WiredTiger.lock: handle-open: open: Permission denied”}}
BUT – what if we SU to mongod and run it:
su mongod -c “mongod -f /etc/mongod.conf”
It WORKS just fine – Mongo daemon starts up just fine.
Its only an issuer when starting from systemctl
Example 2. Database port — lets change the port
storage:
dbPath: /var/lib/mongo
network interfaces
net:
port: 26019
When we start with systemctl it FAILS with BIND issue
systemctl start mongod –
{“t”:{“$date”:“2024-04-17T15:35:44.571-05:00”},“s”:“E”, “c”:“CONTROL”, “id”:20568,
“ctx”:“initandlisten”,“msg”:“Error setting up listener”,“attr”:{“error”:{“code”:9001,“codeName”:
“SocketException”,“errmsg”:“setup bind :: caused by :: Permission denied”}}}
But lets start it with SU
su mongod -c “mongod -f /etc/mongod.conf”
{“t”:{“$date”:“2024-04-17T15:36:52.742-05:00”},“s”:“I”, “c”:“NETWORK”, “id”:23016, “ctx”:“listener”,“msg”:“Waiting for connections”,“attr”:{“port”:26019,“ssl”:“off”}}
IT WORKS just fine
Why do we get permission issues with starting with systemctl – as a service it should start as mongod
When starting it with normal parameters we see the daemon running under mongod.
mongod 159959 1 29 15:38 ? 00:00:00 /usr/bin/mongod -f /etc/mongod.conf