I don't know what is the issue. Why the mongod command is not working now. It was working before. It takes some errors when I write mongod. I am using win32 operation system.
Within the error message it says "Detected unclean shutdown... mongod.lock is not empty"
This means that your mongod was not terminated gracefully - perhaps a hard kill.
In order to start your mongod process again, you'll have to delete this lock file. The path of the file from your error message should be:
C:\data\db\mongod.lock
Here is a link to the relevant documentation where they describe the process of recovering a mongod instance after it was shut down incorrectly.
https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/
I am new to MongoDB. I am trying to install MongoDb 3.0 on Ubuntu 13.0 LTS, which is a VM on Windows 7 Host. I have installed MongoDB successfully (packages etc.), but when I execute the command sudo service mongod start, I get the following error in the "/var/log/mongodb/mongod.log" log file. Can anyone help me understanding this error. There is nothing on internet related to this.
2015-04-23T00:12:00.876-0400 I CONTROL ***** SERVER RESTARTED *****
2015-04-23T00:12:00.931-0400 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-04-23T00:12:00.931-0400 I - [initandlisten] Fatal Assertion 28578
2015-04-23T00:12:00.931-0400 I - [initandlisten]
I have fixed this issue myself, by deleting the mongodb-27017.sock file . I ran the service after deleting this file, which worked fine. However, I am still not sure the root cause of the issue. The output of the command ls - lat /tmp/mongodb-27017.sock is now
srwx------ 1 mongodb nogroup 0 Apr 23 06:24 /tmp/mongodb-27017.sock
Alternative to the answer provided by KurioZ7, you can simply set the permissions of the .sock file to the current user:
sudo chown `whoami` /tmp/mongodb-27017.sock
This does the trick for me if I want to run mongod without sudo. If I delete the file like in KurioZ7s answer, I will simply get the same error the next time I restart my machine.
This issue occurs when you use the command
mongod
Before using the command
sudo service mongod start
To fix the issue, either:
Set appropriate permissions on the file:
/tmp/mongodb-27017.sock
OR
Remove the file
/tmp/mongodb-27017.sock
Run
sudo service mongod start && mongod
The most likely cause for this was that the mongod process was at some point started by the root user. The socket file (/tmp/mongodb-27017.sock) was therefore owned by the root user. The mongod process usually runs under its own dedicated user, and that user did not have the permissions to delete that file.
The solution, as you already found out, was to delete it. Then mongodb was able to recreate it with the correct permissions. This should persist after reboot, as long as mongodb is started using the init scripts, or under the correct user account.
$ sudo mongod
it solve problem for me
Change the ownership mongodb-27017.sock file in /tmp directory and start the mongod again.
cd /tmp
sudo chown mongodb:mongodb mongodb-27017.sock
sudo systemctl start mongod
For UNIX-based operating systems, as an alternative to the answer provided by Bastronaut, you could also specify the .sock file to be saved to a folder over which mongod has full user rights (corresponding to the way you are running mongod), that way mongod will also be able to remove the .sock file upon shutdown. The default folder to which the .sock file is saved is '/tmp'. To specify another folder, use a custom mongodb configuration file, for instance 'mongodb.conf', and add the following to it:
net:
unixDomainSocket:
pathPrefix: "anotherFolder"
After which you can run mongod with the command:
$ mongod --config /path/to/mongodb.conf
You can read the documentation on: https://docs.mongodb.org/manual/reference/configuration-options/#net.unixDomainSocket.pathPrefix
Manually restarting mongod service after restart fixed the problem.
Long-term solution was to add static host name, instead of ip address 'net' part of mongod.conf file (I suspect the problem is that ip address is not yet given to server, when mongod servis starts).
If you are having this problem using docker, refer to this question:
MongoDB docker container “Failed to unlink socket file”
I have mongodb installed on a new Amazon Linux AMI after implementing the guide here. When running "service mongod start" though, I just get a Starting mongod FAILED message. Nothing else. Blank log file also.
service mongod stop yields a FAILED also.
service mongod status yields "mongod is stopped"
Any thoughts or next steps?
I faced the same problem with my master mongodb instance. I have a replica set of 3 instances on EC2 and I had the same problem after one reboot that we needed for it, mongod simply failed to start.
First thing I did, was changed the ownership of the log file that is set up in the mongod.conf:
sudo chown mongod:mongod <LOG FILE>
After this I tried only sudo mongod and this will log the problem why the service won't start in the log file.
Mine appeared to be some ownership issues with the WiredTiger conf files in the dbPath directory (were set to root ownership instead to mongod user)
What I do in that case is use
sudo killall mongod
and after that it starts ok. My suspicion is that there is a running instance and that's why it fails to start.
I have installed mongodb using macports. I can run mongod from the terminal with
sudo mongod --dbpath /opt/local/var/db/mongodb
When I try to run it with:
sudo port load mongodb
mongod fails to start. The log file shows repeated attempts to start, each of them including the message
info preallocateIsFaster couldn't run due to: couldn't open file /opt/local/var/db/mongodb/journal/tempLatencyTest for writing errno:13 Permission denied; returning false
There is no such file, but the directory exists. It is owned by root with group _mongo. Changing its ownership to _mongo resulted in other problems. I also tried
mongod --repair
and although that had fixed a problem with the lock file it isn't fixing this one. Help appreciated.
I am running Mongodb server as an daemon process,I suspect that the mongo gets crashed and restarted. Is there any file available to confirm the crash.I believe that everyone acquainted about mysql if its get killed and restarted. we can confirm by checking the file. In that same way we do have a file in Mongodb to check it?
By default mongod sends its logs to stdout. From the mongod --help output:
--logpath arg file to send all output to instead of stdout
--logappend append to logpath instead of over-writing
i.e. you can specifiy a log file for the daemon - or you could just use a shell redirection.
You should have a look at how your deamon process is started to find if and where a log file is written.
Some information on your system might also help us be more helpful.