Not the answer you need?
Register and ask your own question!

Could not able to start mongod as a service

AlisherAlisher Current User Role Novice

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)

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)

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

Can any one please help me out with this.

Thanks and Best Regards,

Alisher.

Answers

  • Evgeniy PatlanEvgeniy Patlan Percona Percona Staff Role

    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

  • AlisherAlisher Current User Role Novice

    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.

  • vinicius.grippavinicius.grippa Percona Percona Staff Role

    Alisher,

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

  • Evgeniy PatlanEvgeniy Patlan Percona Percona Staff Role

    @Alisher

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

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

    [Unit]

    Description=MongoDB Database Server

    Documentation=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

  • AlisherAlisher Current User Role Novice

    Hi @Evgeniy and vinicius.grippa

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

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

    Below screen shot of updated mongod.conf file

    Below screen shot permissions for mongod.conf file

    Below screen shot for directories with permissions

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

    Thanks and Regards,

    Alisher.

  • Evgeniy PatlanEvgeniy Patlan Percona Percona Staff Role

    @Alisher

    What are the permissions for /home/mongod?

  • AlisherAlisher Current User Role Novice

    @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.


    [[email protected] home]$ sudo service mongod start

    Redirecting to /bin/systemctl start mongod.service

    [[email protected] 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: https://docs.mongodb.org/manual

     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.

    [[email protected] home]$ 

  • Evgeniy PatlanEvgeniy Patlan Percona Percona Staff Role

    @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

  • Akira KuroganeAkira Kurogane Percona Percona Staff Role

    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.

  • BroncoBronco Entrant Current User Role Contributor

    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

  • BroncoBronco Entrant Current User Role Contributor

    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)

Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.