unable to start mongod as a service but am able to start it from shell

3,955 views
Skip to first unread message

Upendra Sharma

unread,
Dec 6, 2018, 3:15:29 PM12/6/18
to mongodb-user
Hi All,
I am facing a weird problem.
I am unable to start mongod using systemd but when I sudo mongodb and try to start the daemon it works fine. We have checked the permissions of all files, namely dbpath, pid and logs files, and they all belong to the user mongodb.

-- failure to start as a service -- 
[root@cm-db-1 mongo]# systemctl status mongod.service
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2018-12-05 21:41:11 UTC; 56s ago
  Process: 6991 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=100)
 Main PID: 24086 (code=exited, status=0/SUCCESS)

Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net systemd[1]: Starting High-performance, schema-free document-oriented database...
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net mongod[6991]: about to fork child process, waiting until server is ready for connections.
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net mongod[6991]: forked process: 7032
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net mongod[6991]: ERROR: child process failed, exited with error number 100
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net systemd[1]: mongod.service: control process exited, code=exited status=100
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net systemd[1]: Failed to start High-performance, schema-free document-oriented database.
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net systemd[1]: Unit mongod.service entered failed state.
Dec 05 21:41:11 cm-db-1.ci80.lsf04.ibmwhc.net systemd[1]: mongod.service failed.

-- successful start from commandline --
-bash-4.2$ /usr/bin/mongod --quiet -f /etc/mongod.conf run
about to fork child process, waiting until server is ready for connections.
forked process: 30878
child process started successfully, parent exiting

Upendra Sharma

unread,
Dec 6, 2018, 8:57:31 PM12/6/18
to mongodb-user
Found out the root cause and the fix:
Root Cause: the security context of mongodb data files had changed; I could confirm it by comparing the results of ls -Z data files between a working server and the failed one. 
Fix: resetting it with chcon fixed the problem.
Reply all
Reply to author
Forward
0 new messages