1

I have been following official guide for installing mongodb but it wont run as a service. When i try

$ whereis mongod
mongod: /usr/bin/mongod /etc/mongod.conf /usr/share/man/man1/mongod.1.gz

but step from the guide for starting the service

$ sudo service mongod start
mongod: unrecognized service
1
  • Check /etc/init.d/mongodb or /etc/init.d/mongod and /etc/rc0.d ... /etc/rc6.d symlinks are exists. Also check service --status-all output and mongodb-org.deb content. Commented Aug 28, 2022 at 6:02

2 Answers 2

2

It looks that you can't install mongodb-org-server package if you don't have systemd even though there is section about configuring it post install on mongodb docs. In order to make it work I downloaded package from theirs download center for my distribution and found and analyzed the service script.

ExecStart=/usr/bin/mongod --config /etc/mongod.conf

So in order to run server just ensure that you have folders from your mongod.conf and mongod.conf itself. You probably have those after failed installation but even if you don't you can create folders and take mongod.conf from downloaded archive. By default folders they are /var/lib/mongodb and /var/log/mongodb use this command to create them if they don't exist and location for mongod.conf is /etc/mongod.conf

sudo mkdir -p /var/log/mongodb /var/lib/mongodb

Also you have to ensure that user who is running has permission to access folders. If that is not your current user, then put that user instead of `whoami`

sudo chown `whoami` /var/lib/mongodb /var/log/mongodb/

Now you can run your server manually with

mongod --config /etc/mongod.conf

Here is the whole mongod.server from archive if anyone is interested

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

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

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

[Install]
WantedBy=multi-user.target

0

Check output of ls /etc/init.d/*mongo* and service --status-all to find out exact service name

You must know what init system used in your system.

Googled for you:

https://wiki.debian.org/Init#Determining_the_init_system

From your link (https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-debian/):

Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command).

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

6
  • I did checked what system I am using there is a section in the guide I referred to just before the section you just quoted. So that is how I know I am supposed to use service instead of systemctl command Commented Aug 27, 2022 at 16:13
  • So you should know you may check /etc/init.d/mongod and /etc/rc0.d ... /etc/rc6.d symlinks are installed. Also check service --status-all output and mongodb-org.deb content. Commented Aug 27, 2022 at 16:55
  • I did this also there is no service Commented Aug 28, 2022 at 9:10
  • So mongodb deb package from mongodb site package do not have these files. I guess it supports systemd only. Check outpout of dpkg -L mongodb-org. Also why you dont use mongodb from debian repo. Commented Aug 28, 2022 at 10:14
  • I finally resolved issue, you can read about it in my answer if you are interested Commented Aug 28, 2022 at 10:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.