other services like apache2, etc are working fine.
But when I type sudo service mongod start I get this error:
mongod: unrecognized serviceI have this file:
/lib/systemd/system/mongod.service It says this:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --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
#
[Install]
WantedBy=multi-user.target 2 3 Answers
I had the same problem after pulling the ubuntu:17:04 docker image and installing mongodb-org
It looks like Mongodb created a systemd startup file which was already replaced by upstart.
As a workaround:
Create a new file
/etc/init/mongod.conf(requires sudo rights). You can use:sudo gedit /etc/init/mongod.confPaste the following contents into the newly created upstart file:
# Ubuntu upstart file at /etc/init/mongod.conf # Recommended ulimit values for mongod or mongos # See # limit fsize unlimited unlimited limit cpu unlimited unlimited limit as unlimited unlimited limit nofile 64000 64000 limit rss unlimited unlimited limit nproc 64000 64000 kill timeout 300 # wait 300s between SIGTERM and SIGKILL. pre-start script DAEMONUSER=${DAEMONUSER:-mongodb} if [ ! -d /var/lib/mongodb ]; then mkdir -p /var/lib/mongodb && chown mongodb:mongodb /var/lib/mongodb fi if [ ! -d /var/log/mongodb ]; then mkdir -p /var/log/mongodb && chown mongodb:mongodb /var/log/mongodb fi touch /var/run/mongodb.pid chown $DAEMONUSER /var/run/mongodb.pid end script start on runlevel [2345] stop on runlevel [06] script ENABLE_MONGOD="yes" CONF=/etc/mongod.conf DAEMON=/usr/bin/mongod DAEMONUSER=${DAEMONUSER:-mongodb} DAEMONGROUP=${DAEMONGROUP:-mongodb} if [ -f /etc/default/mongod ]; then . /etc/default/mongod; fi # Handle NUMA access to CPUs (SERVER-3574) # This verifies the existence of numactl as well as testing that the command works NUMACTL_ARGS="--interleave=all" if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null then NUMACTL="$(which numactl) -- $NUMACTL_ARGS" DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"} else NUMACTL="" DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"} fi if [ "x$ENABLE_MONGOD" = "xyes" ] then exec start-stop-daemon --start \ --chuid $DAEMONUSER:$DAEMONGROUP \ --pidfile /var/run/mongodb.pid \ --make-pidfile \ --exec $NUMACTL $DAEMON $DAEMON_OPTS fi end scriptNow, you can use the following commands:
sudo service mongod startsudo service mongod stopsudo service mongod status
reference:
1I kept getting the same error when trying to start the mongo service. mongod worked, but then I need to keep one terminal window open to use mongo in another. nothing else worked for me except this:
'mongod --fork --logpath /var/log/mongodb.log'
Above command starts the mongo daemon if you don't already have it started and then you can just type 'mongo' in command line and mongo works
(from here: )
1I removed mongo lock file first
sudo rm /var/lib/mongodb/mongod.lockthen started the mongod using the following command
sudo mongod --fork -f /etc/mongod.conf