0

I am trying to install mongodb 3.4 on Redhat 7.9. When I start mongodb systemctl start mongod I get the below error FileNotOpen: Failed to open "/data1/mongodb/log/mongod.log, But when I start mongodb manually I don't see any issue mongod -f /etc/mongod.conf.

from /data1/mongodb/log/mongod.log I see this error, not sure why it's saying /data/db/mongod.lock

2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] MongoDB starting : pid=1434 port=27017 dbpath=/data/db 64-bit host=gcppaadmdb01.liverpool.com.mx
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] db version v3.4.24
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] git version: 865b4f6a96d0f5425e39a18337105f33e8db504d
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] allocator: tcmalloc
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] modules: none
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] build environment:
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten]     distmod: rhel70
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten]     distarch: x86_64
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten]     target_arch: x86_64
2021-05-21T15:10:40.688-0500 I CONTROL  [initandlisten] options: { processManagement: { fork: true }, systemLog: { destination: "file", path: "/data1/mongodb/log/mongod.l
og" } }
2021-05-21T15:10:40.689-0500 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to lock file: /data/db/mongod.lock Resource temporarily unavailable. Is a mo
ngod instance already running?, terminating
2021-05-21T15:10:40.689-0500 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2021-05-21T15:10:40.689-0500 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2021-05-21T15:10:40.689-0500 I CONTROL  [initandlisten] now exiting
2021-05-21T15:10:40.689-0500 I CONTROL  [initandlisten] shutting down with code:100
[root@gcppaadmdb01 ~]# ls -lrt /data/db/mongod.lock
-rwxrwxrwx. 1 mongod mongod 0 May 24 21:18 /data/db/mongod.lock

Before error

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2021-05-20 23:38:54 CDT; 3min 14s ago
     Docs: https://docs.mongodb.org/manual
  Process: 3698 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
  Process: 3694 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 3690 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 3687 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

May 20 23:38:54 mongodb.test.com systemd[1]: Starting MongoDB Database Server...
May 20 23:38:54 mongodb.test.com mongod[3698]: 2021-05-20T23:38:54.076-0500 F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open "/data1/mongodb/log/mongod.log"
May 20 23:38:54 mongodb.test.com systemd[1]: mongod.service: control process exited, code=exited status=1
May 20 23:38:54 mongodb.test.com systemd[1]: Failed to start MongoDB Database Server.
May 20 23:38:54 mongodb.test.com systemd[1]: Unit mongod.service entered failed state.
May 20 23:38:54 mongodb.test.com systemd[1]: mongod.service failed.

Permissions on /data1/ folder looks good

[root@mongodb]# ls -l /data1/
total 20
drwxr-xr-x. 4 mongod mongod  4096 May 20 23:38 mongodb
[root@mongodb]# ls -l /data1/mongodb/log/mongod.log                                                                                                                                          
-rw-r--r--. 1 mongod mongod 3846 May 20 23:42 /data1/mongodb/log/mongod.log

mongod.conf file [root@mongodb]# cat /etc/mongod.conf
storage: dbPath: /data1/mongodb/data journal: enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /data1/mongodb/log/mongod.log

net:
  port: 27017
  bindIp: 0.0.0.0

System service file

[root@mongodb]# cat /usr/lib/systemd/system/mongod.service 
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
Type=forking
LimitFSIZE=infinity
LimitCPU=infinity
LimitAS=infinity
LimitNOFILE=64000
LimitNPROC=64000
LimitMEMLOCK=infinity
TasksMax=infinity
TasksAccounting=false

1 Answer 1

0

I think that ownership of that log file is not the real problem here. Missing /var/run/mongodb/mongod.pid -file is.

Your mongod.service file describes "PIDFile=/var/run/mongodb/mongod.pid", but in your /etc/mongod.conf file the is no

processManagement:
  fork: true
  pidFilePath: /var/run/mongod/mongod.pid

When you say "systemctl start mongod.service", it will start mongod, but it will kill the process after 5 seconds, because it cannot find that pid-file.

7
  • I made changes to mongod.conf as per your suggestions. now I don't see the permission, but the service is still not up. I see below the error
    – Eva
    May 24, 2021 at 4:17
  • May 23 23:14:25 mongodb.test.com mongod[7794]: about to fork child process, waiting until server is ready for connections. May 23 23:14:25 mongodb.test.com mongod[7794]: forked process: 7796 May 23 23:14:25 mongodb.test.com mongod[7794]: ERROR: child process failed, exited with error number 1 May 23 23:14:25 mongodb.test.com systemd[1]: mongod.service: control process exited, code=exited status=1 May 23 23:14:25 mongodb.test.com systemd[1]: Failed to start MongoDB Database Server.
    – Eva
    May 24, 2021 at 4:17
  • Please check /data1/mongodb/log/mongod.log -file.. What it says when you try to start mongod. Can mongod create that /var/run/mongod/mongod.pid -file?
    – JJussi
    May 24, 2021 at 9:12
  • I have updated the complete error in the question, this is what i see in the logs now 2021-05-21T15:10:40.688-0500 I CONTROL [initandlisten] options: { processManagement: { fork: true }, systemLog: { destination: "file", path: "/data1/mongodb/log/mongod.l og" } } 2021-05-21T15:10:40.689-0500 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to lock file: /data/db/mongod.lock Resource temporarily unavailable. Is a mo ngod instance already running?, terminating
    – Eva
    May 25, 2021 at 2:27
  • Remove that lock file /data/db/mongod.lock and restart mongod. That file exists only when the mongod -process is running and if the process is terminated suddenly, it is not removed and at the next start mongod "thinks" that there is still a process running
    – JJussi
    May 25, 2021 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.