Here comes the result.

My bash prompt is

: steevej ;

: steevej ; systemctl status mongodb
: steevej ; systemctl cat mongodb | grep ExecStart
: steevej ; systemctl cat mongodb | grep User
: steevej ; ls -l /etc/mongodb.conf
: steevej ; systemctl start mongodb
: steevej ; systemctl status mongodb


: steevej ; systemctl status mongodb
○ mongodb.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; preset: disabled)
     Active: inactive (dead)
       Docs: https://docs.mongodb.org/manual

Nov 25 08:55:36 xps13 systemd[1]: Started MongoDB Database Server.
Nov 25 08:58:10 xps13 systemd[1]: Stopping MongoDB Database Server...
Nov 25 08:58:10 xps13 systemd[1]: mongodb.service: Deactivated successfully.
Nov 25 08:58:10 xps13 systemd[1]: Stopped MongoDB Database Server.
Nov 25 08:58:10 xps13 systemd[1]: mongodb.service: Consumed 2.309s CPU time.

: steevej ; systemctl cat mongodb | grep ExecStart
ExecStart=/usr/bin/mongod --config /etc/mongodb.conf

: steevej ; systemctl cat mongodb | grep User
User=mongodb

: steevej ; ls -l /etc/mongodb.conf
-rw------- 1 mongodb mongodb 678 Jul 13 10:42 /etc/mongodb.conf

: steevej ; systemctl start mongodb
● mongodb.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; preset: disabled)
     Active: active (running) since Fri 2022-11-25 09:00:46 EST; 40ms ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 192273 (mongod)
     Memory: 2.0M
        CPU: 23ms
     CGroup: /system.slice/mongodb.service
             └─192273 /usr/bin/mongod --config /etc/mongodb.conf

Nov 25 09:00:46 xps13 systemd[1]: Started MongoDB Database Server.

So even if only mongodb user has read access systemctl still starts correctly. As a note, when I do systemctl start|stop without sudo, I have a dialog that ask for my passwd. So it looks like systemctl does a sudo behind the scene.

More over, if I change the owner of /etc/mongodb.conf so that user mongodb does not have read access, it fails to start with the error Error opening config file: Permission denied.

If I remove the configuration, it fails with Error opening config file ‘/etc/mongodb.conf’: No such file or directory. The error message is a little bit more explicit but I am using a more recent version:

: steevej ; mongod --version
db version v5.0.3

So the only conclusion I can make is that the configuration file does not exist.

3 Likes