Cannot restart mongodb - mongodb

I am trying to restart my mongodb but it has an error
this is the error:
[root#testdb vagrant]# sudo service mongod restart
Stopping mongod: [FAILED]
Starting mongod: warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
about to fork child process, waiting until server is ready for connections.
forked process: 6843
ERROR: child process failed, exited with error number 100
[FAILED]
my config file is:
bind_ip = 0.0.0.0
dbpath = /var/lib/mongodb
fork = true
logappend = true
logpath = /var/log/mongodb/mongodb.log
nojournal = false
pidfilepath = /var/run/mongodb/mongodb.pid
port = 27017
rest = false
smallfiles = false
this is my log
this is the output of ps ax | grep mongod
1935 ? Sl 1:53 /usr/bin/mongod --config /etc/mongodb.conf
5592 pts/0 S+ 0:00 tail -f /var/log/mongodb/mongodb.log
5889 pts/1 S+ 0:00 grep mongod
i also removed /var/lib/mongodb/mongod.lock
when i restart this is the output stop failed.
Stopping mongod: [FAILED]
Starting mongod: warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
about to fork child process, waiting until server is ready for connections.
forked process: 5874
child process started successfully, parent exiting
[ OK ]

Most likely either a permissions issue or a incorrect shutdown.
Run commands sudo rm /var/lib/mongodb/mongod.lock to remove the lock on mongod process then chown the directory to the mongod user using
chown-R mongod: mongod /var/lib/mongo
then start service sudo service mongod start

Before I try and give my input, here is the MongoDB documentation for processes:
http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/#StartingandStoppingMongo-SendingshutdownServer%28%29messagefromthemongoshell
That being said, trying shutting down the server:
use admin
db.shutdownServer()
and starting it again.
If you're using linux:
mongod --shutdown
I hope this helped a little, or atleast you can try and use the documentation.

Related

mongoDB: child process failed, exited with 1 & 14

I have already tried it with the following thread but it didn't help me:
ERROR: child process failed, exited with error number 1,mongodb
Tried that:
sudo mongod --fork --config /etc/mongod.conf --logpath /var/log/mongodb/mongod.log
Result:
forked process: 2887
ERROR: child process failed, exited with 48
To see additional information in this output, start without the "--fork" option.
Tried the following as well:
sudo systemctl start mongod
One of the lines in the error message say:
ERROR: child process failed, exited with 14
Would appreciate any help. mongod was working pretty well until I have started trying to implement a replica set.
Use this command on the terminal:
sudo mongod --dbpath /System/Volumes/Data/data/db
It should start the MongoDB server and allocate a port for it. You can exit out of the server and then try the command again and it should work.

Can't start mongodb through systemctl, error logs won't show up

I cannot boot MongoDB via systemctl.
When I try, I get an error, but nothing comes through the log.
When I try and run it manually via $ /usr/bin/mongod --config /etc/mongod.conf no error message comes through the log.
When I turn off logging in mongod.conf, an error message comes out that I don't have rights to the directory with the data (which is to be expected).
However, I can boot the process with sudo such as:
$ sudo /usr/bin/mongod --config /etc/mongod.conf, the process runs but it is tied to my terminal so if my session closes so does MongoDB. Hence why I am trying to run it with systemctl.
Then when I try and run with sudo in my service such as:
ExecStart=/usr/bin/sudo /usr/bin/mongod --config /etc/mongod.conf
Then it doesn't start and no error log comes through.
My conf file:
# mongod.conf
# for documentation of all options, see:
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
My service:
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
Restart=always
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/sudo /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
So it becomes an impossible question. When I try and boot it through systemctl no error log comes through /var/log/mongodb/mongod.log. If I run it manually I get an error saying that I don't have access to the data folder since the data folder is owned by the mongodb user, which is expected.
What can I do to see what is causing my service above to fail? I don't want to use sudo in my ExecStart command but whether I do or I don't I get the same problem: the service fails to start and no logs come through my Mongo log file.
Check of your service is failed
systemctl is-failed mongodb.service
Get failure logs
Journalctl is a utility for querying and displaying logs from journald, systemd's logging service.
get latest 20 lines of logs which will you failure details
journalctl | grep mongod | tail -n20
Use journalctl -u service and tail to get top 20 logs
journalctl -u mongodb.service | tail -n20
Get list of all failed services
systemctl list-units --failed
Read - https://www.cyberciti.biz/faq/systemd-systemctl-list-all-failed-units-services-on-linux/

Can't start mongoDB as a service

I'd like to run mongoDB as a service. The instance shall be configured as a single-node replicaset to be able to connect a elasticSearch instance to it with a the connector.
So I extended the mongod.conf:
...
replication:
replSetName: "singleNodeRepl"
...
I tried different ways to start now the mongod, but nothing works.
When I try to start the service by $ service mongod start, following error is thrown:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.106" (uid=1225 pid=26018 comm="start mongod ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
When I execute this command as sudo (whats not best-practise, right?), its "running" and following message is shown:
mongod start/running, process 26034
But process 26034 doesn't exist and ps aux | grep mongo also shows nothing?!
Next try: Run it as a normal application
mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl
Here following exception is shown:
2016-04-08T14:31:35.192+0200 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-04-08T14:31:35.192+0200 I CONTROL [initandlisten] dbexit: rc: 100
Everything is fine when I run ~$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl, but thats not my target: Its not running as a service and its running as root.
The mongod-logfile often keeps untouched. But the last lines are curious:
2016-04-08T14:24:56.242+0200 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-04-08T14:24:56.242+0200 I - [initandlisten] Fatal Assertion 28578
2016-04-08T14:24:56.242+0200 I - [initandlisten]
***aborting after fassert() failure
A mongodb-27017.sock existed, but deleting (what was suggested anywhere) didn't help.
Based on the erros above if tried serveral solutions, but nothing helps.
I think it's a very simple mistake...but which one?
[edit:]
I discovered, that I perhaps should have specified the config-location. So the (working but bad) command looks like:
$ sudo mongod --dbpath /var/lib/mongodb/ --replSet SingleNodeRepl --config /etc/mongod.conf
This brings following error:
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
Thats an old thing, which was the solution for this problem and suddenly doesn't work anymore!?
I've had issues stopping and starting mongod as a service. Turns out there was an issue with the upsart script.
I found this discussion which seemed to fix it.
The suggested solution was pretty much: (copy pasting now)
vim /etc/init.d/mongod
look for stop() function (and start() function for good measure) and remove quotes around $PIDFILE in the following line.
killproc -p $PIDFILE -d 300 /usr/bin/mongod
Do this:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start
Let me know if this doesn't work!

MongoDB: replSet can't get local.system.replset config from self or any seed "server is not running with --replSet"

I try to setup a Replica Set on Ubuntu 14.04 x64.
First error I run into when trying
$ sudo mongod --port 27017 --replSet rs0:
replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
I read that > rs.initiate() solves that issue, so I do
$ sudo service mongod start
$ mongo
rs.initiate()
which throws:
{ "ok" : 0, "errmsg" : "server is not running with --replSet" }
So if I can't start mongod with --replSet how can I solve the error within rs.initiate() which I need to solve the first error?
It's like a vicious circle!
Solved the problem by using a second command shell:
console1:
$ sudo mongod --port 27017 --replSet rs0
console2:
$ mongo
> rs.initiate()
you can set this replSet in /etc/mongodb.conf file,
# Replication
replication:
replSetName: rs0
#fork
processManagement:
fork: true
Fork for running in background.
Now start mongod,
mongod --config /etc/mongod.conf
To check the process status,
ps aux | grep mongod
Refer : https://docs.mongodb.org/manual/administration/configuration/

unable to connect to mongodb on localhost

I have installed MongoDB:
user#user-workshop:~$ sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 7980
user#user-workshop:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Mon Mar 3 21:43:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
user#user-workshop:~$
but as you can see, I'm unable to connect to it. What can I do about it?
Try running these commands:
rm /data/db/mongod.lock
mongod --dbpath /data/db --repair
mongod --dbpath /data/db
For more details read: mongodb manual