0

I am having a service file for mongodb at /lib/systemd/system/mongod.service

and my file contains following data as below

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --fork --config /etc/mongod.conf
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

So while Running the Command as below

sudo /usr/bin/mongod --quiet --fork --config /etc/mongod.conf

my command running successfully but coming to Service File it is getting Error due to No Root Access.

So i want to run my systemd service file as root access.Any Suggestion would be appreciated and thanks in advance

Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54
  • 1
    This really should be asked on [dba,stackexchange.com](https://dba.stackexchange.com) which is for questions and answers relating to database administration and configuration. StackOverflow is for :"programming" based questions, of which this is not. Please move your post to the appropriate site instead of posting here. – Neil Lunn Jun 13 '17 at 05:00
  • I am not asking about database @Neil Lunn , i am asking question about systemd service file and how to run it with root access and Thanks for replying my post – Ratan Uday Kumar Jun 13 '17 at 07:35
  • Which is **not** a programming question. So you are posting on the wrong site. Understand now? – Neil Lunn Jun 13 '17 at 07:36
  • What is the error and what is the command you are using to run mongo as a systemd service? And, to nitpick, these files are called Unit files, as in systemd units. I am not sure service file is the right term. – SRC Jun 13 '17 at 14:00
  • i am using `sudo systemctl start mongod.service` for starting and `sudo systemctl status mongod.service` – Ratan Uday Kumar Jun 14 '17 at 10:31
  • I have Solved my issue by using 'sudo chown -R mongodb:mongodb /var/lib/mongod' and 'sudo chown -R mongodb:mongodb /var/log/mongodb' ` – Ratan Uday Kumar Jun 15 '17 at 14:05
  • Ok will ask to stackexchange next time – Ratan Uday Kumar Jun 15 '17 at 14:06

2 Answers2

2

Solved the Issue to Run the Service as daemon , i have to give full privileges to Mongodb database and Log path for User=mongodb & Group=mongodb by running below commands

sudo chown -R mongodb:mongodb /var/lib/mongodb

sudo chown -R mongodb:mongodb /var/log/mongodb
Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54
0

The mongodb.service files normally includes:

User=mongodb
Group=mongodb

So your problem is elsewhere. You should post the exact error you describing as "Error due to No Root Access" and the command you run that generates it.

In the future, a better site for systemd related questions is http://unix.stackexchange.com

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49