# Could not able to start mongod as a service

**URL:** <https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278>\
**Category:** MongoDB® General Discussion\
**Created:** [November 16, 2020, 5:46am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278 "2020-11-16T05:46:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alisher](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@Alisher](https://forums.percona.com/u/Alisher)\
**Post date:** [November 16, 2020, 5:46am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/1 "2020-11-16T05:46:11Z")

</div>

Dear Champs,

I want to start mongod as a service, but I could not able to do that I am facing errors.

I installed mongo community server 4.2 rpm packages on redhat linux 7 I wanted to use my own mongod.conf file rather than the default once. (find the attached mongod.conf file for reference)

[mongod.conf.txt](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/3176f6ebd9a4502be7cb29424fe7774a9ba99da2.txt)

As to start mongod as a service which means (sudo service mongod start) I edited the systemd/system/mongod.service file (find the attached mongod.service file)

[mongod.service.txt](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/8c56c84d47f64120fc0821d857d243fa32fe909a.txt)

After above all when I try to start mongod I am getting below error.

 ![start error1.jpeg](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/b88e6a8cc4fa0147fe10525c97b1a676656af9b0.jpeg)

Can any one please help me out with this.

Thanks and Best Regards,

Alisher.

[mongod.conf.txt](https://forums.percona.com/uploads/short-url/73Ah8sMQDi0lUNVcr7hg4j7P7cC.txt) (488 Bytes)

[mongod.service.txt](https://forums.percona.com/uploads/short-url/k1uM8kjDffjHeHtTR7cjqq10Vke.txt) (255 Bytes)

---

<div class="post-metadata">

**Author:** ![Evgeniy\_Patlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/evgeniy_patlan/32/41_2.png) [@Evgeniy\_Patlan](https://forums.percona.com/u/Evgeniy_Patlan)\
**Post date:** [November 16, 2020, 6:36am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/2 "2020-11-16T06:36:06Z")

</div>

hi @Alisher

As I can see from the provided screenshot mongod service couldn’t read config file due to incorrect permissions

“Error reading config file: Permission denied” So please check permissions.

Also after the modifications of systemd unit-file it is recommended to run `sudo systemctl daemon-reload` before starting service

---

<div class="post-metadata">

**Author:** ![Alisher](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@Alisher](https://forums.percona.com/u/Alisher)\
**Post date:** [November 16, 2020, 6:42am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/3 "2020-11-16T06:42:30Z")

</div>

I gave 755 permissions to config file and also after the modifications on systemd unit-file I executed “sudo systemctl daemon-reload” but no luck.

---

<div class="post-metadata">

**Author:** ![vinicius.grippa](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vinicius.grippa/32/1246_2.png) [@vinicius.grippa](https://forums.percona.com/u/vinicius.grippa)\
**Post date:** [November 16, 2020, 6:49am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/4 "2020-11-16T06:49:09Z")

</div>

Alisher,

Please provide the log and the new error message after applying Evgenity suggestions.

---

<div class="post-metadata">

**Author:** ![Evgeniy\_Patlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/evgeniy_patlan/32/41_2.png) [@Evgeniy\_Patlan](https://forums.percona.com/u/Evgeniy_Patlan)\
**Post date:** [November 16, 2020, 8:33am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/5 "2020-11-16T08:33:45Z")

</div>

@Alisher

You need to modify your systemd unit-file in the following way:

===========================================

[Unit]

Description=MongoDB Database Server

Documentation=[https://docs.mongodb.org/manual](https://docs.mongodb.org/manual)

After=network.target

[Service]

User=mongod

Group=mongod

Environment=“OPTIONS=-f /home/mongod/config/mongod.conf”

ExecStart=/usr/bin/mongod $OPTIONS

[Install]

WantedBy=multi-user.target

============================================

Also in mongod.conf please remove

fork: true

Additionally

permissions on your /home/mongod directory and it’s subdirectories should be

owner - mongod

group - mongod

and permissions 755

With such setup I was able to correctly start mongod

---

<div class="post-metadata">

**Author:** ![Alisher](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@Alisher](https://forums.percona.com/u/Alisher)\
**Post date:** [November 17, 2020, 1:36am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/6 "2020-11-17T01:36:50Z")

</div>

Hi @[Evgeniy](https://forums.percona.com/profile/Evgeniy%20Patlan) and [vinicius.grippa](https://forums.percona.com/profile/vinicius.grippa)

I deployed as per the above comments again I am facing same issue.

 ![service start error.PNG](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/bf564d30088a84e59e2ee74a17dbabe58bf5522f.png)

Below is updated mongod.service file , after updating the mongodb.service file I even did ‘sudo systemctl daemon-reload’

![mongod service.PNG](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/94ff1830dd40b5072bc3099e084da84ebd2fb469.png)

Below screen shot of updated mongod.conf file

 ![mongo conf file.PNG](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/6311019d287ce195d35153f85b98cc85c2970636.png)

Below screen shot permissions for mongod.conf file

 ![config file permissions.PNG](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/4396b36c99001b0898b59fa9d6a2ef0a87fec8ef.png)

Below screen shot for directories with permissions

 ![directory permissions.PNG](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/80b9d3f4b7e112dfbb069ffecb6e4260dec29d98.png)

If I try to check log file , it didn’t even get created.

 ![no log file.PNG](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/1X/e79b267214ed3dfbb03ca26171cb8610ed211f04.png)

Thanks and Regards,

Alisher.

---

<div class="post-metadata">

**Author:** ![Evgeniy\_Patlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/evgeniy_patlan/32/41_2.png) [@Evgeniy\_Patlan](https://forums.percona.com/u/Evgeniy_Patlan)\
**Post date:** [November 17, 2020, 1:41am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/7 "2020-11-17T01:41:29Z")

</div>

@Alisher

What are the permissions for /home/mongod?

---

<div class="post-metadata">

**Author:** ![Alisher](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@Alisher](https://forums.percona.com/u/Alisher)\
**Post date:** [November 17, 2020, 2:19am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/8 "2020-11-17T02:19:26Z")

</div>

@Evgeniy_Patlan

Below are the permissions for /home and /mongod

drwxr-xr-x. 3 root root 20 Nov 17 05:04 home

drwxr-xr-x. 8 mongod mongod 180 Nov 17 06:29 mongod

even though I am getting below error when I start.

[mongod@mongst01 home]$ sudo service mongod start

Redirecting to /bin/systemctl start mongod.service

[mongod@mongst01 home]$ sudo service mongod status

Redirecting to /bin/systemctl status mongod.service

● mongod.service - MongoDB Database Server

Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)

Active: failed (Result: exit-code) since Tue 2020-11-17 07:45:38 UTC; 7s ago

```
 Docs: <a href="https://docs.mongodb.org/manual">https://docs.mongodb.org/manual</a>

```

Process: 2642 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=2)

Main PID: 2642 (code=exited, status=2)

Nov 17 07:45:38 mongst01 systemd[1]: Started MongoDB Database Server.

Nov 17 07:45:38 mongst01 mongod[2642]: Error reading config file: Permission denied

Nov 17 07:45:38 mongst01 mongod[2642]: try ‘/usr/bin/mongod --help’ for more information

Nov 17 07:45:38 mongst01 systemd[1]: mongod.service: main process exited, code=exited, status=2/INVALIDARGUMENT

Nov 17 07:45:38 mongst01 systemd[1]: Unit mongod.service entered failed state.

Nov 17 07:45:38 mongst01 systemd[1]: mongod.service failed.

[mongod@mongst01 home]$

---

<div class="post-metadata">

**Author:** ![Evgeniy\_Patlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/evgeniy_patlan/32/41_2.png) [@Evgeniy\_Patlan](https://forums.percona.com/u/Evgeniy_Patlan)\
**Post date:** [November 17, 2020, 2:26am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/9 "2020-11-17T02:26:57Z")

</div>

@Alisher

the main issue is:

Error reading config file: Permission denied

So you should carefully check check permissions, also maybe you can find some additional information in /var/log/messages

---

<div class="post-metadata">

**Author:** ![Akira\_Kurogane](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/akira_kurogane/32/1280_2.png) [@Akira\_Kurogane](https://forums.percona.com/u/Akira_Kurogane)\
**Post date:** [November 17, 2020, 2:37am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/10 "2020-11-17T02:37:56Z")

</div>

Evegniy - I believe that _fork_ should be true in the config file.

Although we used stdout log capture into journald with PBM, and PBM doesn’t have a fork option (yet), it would be pretty uncommon to run mongod that way. Whether MongoDB Community edition or Percona Server for MongoDB.

---

<div class="post-metadata">

**Author:** ![Bronco](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@Bronco](https://forums.percona.com/u/Bronco)\
**Post date:** [November 27, 2020, 11:51am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/11 "2020-11-27T11:51:29Z")

</div>

Please try to run it manually on the command line, with mongod user

/usr/bin/mongod -f /home/mongod/config/mongod.conf

This will tell you that you have a strange parameter on the your conf file.

You don’t have a log file because mongod never started. (or mongod can not write to /home/mongod/logs)

Make sure that mongod user can write on the directories /home/mongod/logs and /home/mongod/data.

A simple touch should do the trick with your mongod user

touch /home/mongod/logs/PleaseDeleteMe

touch /home/mongod/logs/data

(Your service file shouldn’t be a concern at this point.)

Make sure:

- that you don’t have a **sock** file (normally on /tmp) owned by root. The same for **pid** file and for **log** file (log file doesn’t seem to exist)

-That all locations that mongod needs to write are writable by mongod

If the problem is still happening:

I would replace with a normal conf file and adapt it slowly to your requirements. (yaml notation is very picky).

Try it until you get it started. on every attempt try a “less /home/mongod/logs/mongod.log”

If it starts on the command line you can normally kill it by a simple kill \<pid\_of\_the\_mongod\_process\>.

From this point try to start using the service

---

<div class="post-metadata">

**Author:** ![Bronco](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@Bronco](https://forums.percona.com/u/Bronco)\
**Post date:** [November 27, 2020, 12:02pm UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/12 "2020-11-27T12:02:50Z")

</div>

BTW

I tried with your original conf file and it works. (I have changed everything from /home to /tmp)

/usr/local/bin/mongod -f ./Downloads/mongod.conf.txt

2020-11-27T17:28:15.098+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’

about to fork child process, waiting until server is ready for connections.

forked process: 28416

child process started successfully, parent exiting

Directory permissions should be the issue. (or existing sock, pid, log file owned by root)

---

<div class="post-metadata">

**Author:** ![Ivan\_Groenewold](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/ivan_groenewold/32/6299_2.png) [@Ivan\_Groenewold](https://forums.percona.com/u/Ivan_Groenewold)\
**Post date:** [November 7, 2025, 11:36am UTC](https://forums.percona.com/t/could-not-able-to-start-mongod-as-a-service/8278/13 "2025-11-07T11:36:47Z")

</div>


