Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Failed to unlink socket file" error in MongoDB 3.0

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]

like image 389
KurioZ7 Avatar asked Apr 23 '15 04:04

KurioZ7


4 Answers

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
like image 117
KurioZ7 Avatar answered Nov 05 '22 11:11

KurioZ7


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.

like image 41
Bastronaut Avatar answered Nov 05 '22 12:11

Bastronaut


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
like image 39
Greg Miller Avatar answered Nov 05 '22 11:11

Greg Miller


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.

like image 12
SpooForBrains Avatar answered Nov 05 '22 10:11

SpooForBrains