I have the following Dockerfile:
FROM debian:wheezy
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 main" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update
RUN apt-get install -y mongodb-org
Then I build the image:
docker build -t my/image .
and try to start and stop the server:
$ docker run -it my/image
root#35ba8193f979:/# service mongod start
[ ok ] Starting database: mongod.
root#35ba8193f979:/# service mongod stop
[FAIL] Stopping database: mongod failed!
As you can see, mongod fails to stop. I can verify this by running ps and grepping for the mongod process; it's still there.
Here's the logs:
root#fce8d9638ce4:/# cat /var/log/mongodb/mongod.log
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] MongoDB starting : pid=19 port=27017 dbpath=/var/lib/mongodb 64-bit host=fce8d9638ce4
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] db version v3.2.9
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] modules: none
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] build environment:
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] distmod: debian71
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] distarch: x86_64
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-09-20T05:01:02.893+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-09-20T05:01:03.087+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2016-09-20T05:01:03.087+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-09-20T05:01:03.156+0000 I NETWORK [initandlisten] waiting for connections on port 27017
I've googled for a solution already; most of the posts I find are very old, or don't describe the same problem as mine. Any help is greatly appreciated.
There appears to be an issue with service mongod stop since internally it calls a command which looks similar to:
start-stop-daemon --stop --pidfile /var/run/mongod.pid --user mongodb --exec /usr/bin/mongod
but the start-stop-daemon command somehow cannot find the executable /usr/bin/mongod, so it failed to stop the process. You can see the service script in /etc/init.d/mongod.
The solution that I found to be working is to call it without --exec directly from the command line:
start-stop-daemon --stop --pidfile /var/run/mongod.pid
and that seems to be able to stop the service properly.
I believe this issue is not limited to MongoDB, since I found multiple references about services not able to be stopped.
Related
I ran mongo server in docker and the logs came up just fine.
2019-04-12T10:39:51.334+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8a03346e57d7
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] db version v3.2.22
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] git version: 105acca0d443f9a47c1a5bd608fd7133840a58dd
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] modules: none
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] build environment:
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] distmod: rhel70
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] distarch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] options: { net: { port: 27017 }, processManagement: { pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/data/db" } }
2019-04-12T10:39:51.339+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
2019-04-12T10:39:51.389+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-04-12T10:39:51.389+0000 I CONTROL [initandlisten]
2019-04-12T10:39:51.406+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2019-04-12T10:39:51.406+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-04-12T10:39:51.406+0000 I NETWORK [initandlisten] waiting for connections on port 27017
But, while connecting the mongodb server from local shell, the connection is getting timedout.
~/mongodb/bin/mongo --host 172.17.0.2
MongoDB shell version v3.6.11
connecting to: mongodb://172.17.0.2:27017/?gssapiServiceName=mongodb
2019-04-12T16:04:45.750+0530 W NETWORK [thread1] Failed to connect to 172.17.0.2:27017 after 5000ms milliseconds, giving up.
2019-04-12T16:04:45.753+0530 E QUERY [thread1] Error: couldn't connect to server 172.17.0.2:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
exception: connect failed
where 172.17.0.2 is the IP obtained by running docker inspect <container-id
I was able to connect mongo shell with in the docker using the command docker exec --it <container-id> bash.
Here's the Docker file for refrence.
RUN echo -e "\
[mongodb]\n\
name=MongoDB Repository\n\
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.2/x86_64/\n\
gpgcheck=0\n\
enabled=1\n" >> /etc/yum.repos.d/mongodb.repo
# Install mongodb
RUN yum update -y && yum install -y mongodb-org
# Set up directory requirements
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]
# Expose port 27017 from the container to the host
EXPOSE 27017
# Start mongodb
ENTRYPOINT ["/usr/bin/mongod"]
CMD ["--port", "27017", "--dbpath", "/data/db", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
Let me know if I am missing something.
Using MacOS
When running:
mongod
I get:
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] MongoDB starting : pid=1160 port=27017 dbpath=/data/db 64-bit host=Interstellar
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] db version v3.4.4
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] allocator: system
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] modules: none
2017-04-30T11:19:56.234+0600 I CONTROL [initandlisten] build environment:
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] distarch: x86_64
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] target_arch: x86_64
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] options: {}
2017-04-30T11:19:56.235+0600 I STORAGE [initandlisten] exception in
initAndListen: 29 Data directory /data/db not found., terminating
2017-04-30T11:19:56.235+0600 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-04-30T11:19:56.235+0600 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] now exiting
2017-04-30T11:19:56.235+0600 I CONTROL [initandlisten] shutting down with code:100
I'm having trouble with this, badly need help
The problem is that if you run "mongod" the default path is /usr/data. NEVERTHELESS macOS Catalina does not accept creating a writable folder there. So after long research, in both here, and reddit, I finally got my server (mongod as well as Mongo) up and running. Try the following these steps:
mkdir -p /System/Volumes/Data/data/db
sudo chown -Rv <your_user_name> /System/Volumes/Data/data/db
sudo mongod --dbpath /System/Volumes/Data/data/db
This may run mongod and start the server. Open another terminal tab, and type Mongo.
First step
brew services start mongodb/brew/mongodb-community#4.4
Second step
cd /Users
whoami
cd to your whoami directory
mkdir data
cd data
mkdir db
mongod --dbpath ~/data/db
Third step
mongo
The problem is that there is no /data/db directory. Please issue this command:
sudo mkdir -p /data/db
If you're not worried about opening up permissions too widely, but just want to ensure that mongodb has permissions to start, you can also issue these commands. They may fix any problems you have if the above command alone doesn't solve things.
cd /
sudo chmod -R 777 data
There are a few posts related Mongodb 3.2, but when I attempted to install 3.4 the startup does not occur. Instead an unusual error appears in the log file (shown at the very end of the listing).
Is this perhaps because of an older version that was installed?
I did do an apt-get remove and purge.
Can anybody suggest why the error appears?
I followed the steps below, as outlined here,
$ sudo apt-get remove mongodb*
$ sudo apt-get purge mongodb*
$ sudo rm -rf /usr/lib/mongodb
$ sudo rm -rf /usr/log/mongodb
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
..
..
E: There were unauthenticated packages and -y was used without --allow-unauthenticated
$ sudo apt-get install mongodb-org # removed -y to get it going
..
..
Setting up mongodb-org (3.4.2) ...
$ sudo chown -R mongodb:mongodb /var/log/mongodb
$ sudo chown -R mongodb:mongodb /var/lib/mongodb # modified ownership in view of what is stated on the mongodb installation note
$ # created the following file
$ cat /etc/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Service 3.4
Wants=network.target
After=network.target
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
# startup
$ sudo systemctl daemon-reload
$ sudo service mongod start
# nothing happens, I then viewed the log file and the following error appears:
$ cat /var/log/mongodb/mongod.log
2017-02-08T22:08:26.155+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] MongoDB starting : pid=11384 port=27017 dbpath=/var/lib/mongodb 64-bit host=12g
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] db version v3.4.2
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] modules: none
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] build environment:
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] distarch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-02-08T22:08:26.178+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
That means the mongod process was started by root user.So you can just remove the sock file or run this command to fix this issue :
sudo chown `whoami` /tmp/mongodb-*.sock
Make sure that the port you assign needs to be accessible and not blocked by your firewall and then just restart the mongod process.
The waiting for connections message in the console output indicates
that the mongod.exe process is running successfully.
You can check out Install MongoDB Community Edition on Ubuntu.
Hope this helps.
#mcgraddy, thanks, that was helpful indeed. Creating the directory and copying the service file was the answer.
$ sudo cp /etc/systemd/system/mongod.service /etc/systemd/system/mongodb.service
$ sudo mkdir -p /data/db
$ sudo chown -R $USER:$USER /data
I had to change ownership for /data.
Starting the service and viewing status shows everything is running as expected:
$ sudo service mongod start
$ sudo systemctl status mongodb
● mongodb.service - MongoDB Database Service
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset:
Active: active (running) since Thu 2017-02-09 13:26:07 GMT; 9min ago
Main PID: 1184 (mongod)
CGroup: /system.slice/mongodb.service
└─1184 /usr/bin/mongod --quiet --config /etc/mongod.conf
Feb 09 13:26:07 systemd[1]: Started MongoDB Database Service.
Newbie here learning node.js and mongodb. I am currently trying to install mongodb on my Mac and faced the following issue when i try to run mongod on terminal.
2016-01-31T12:08:39.791+0800 I CONTROL [initandlisten] MongoDB starting : pid=13733 port=27017 dbpath=/data/db 64-bit host=Joshuas-MBP
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] db version v3.2.1
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] allocator: system
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] modules: none
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] build environment:
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] distarch: x86_64
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] target_arch: x86_64
2016-01-31T12:08:39.792+0800 I CONTROL [initandlisten] options: {}
2016-01-31T12:08:39.794+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-01-31T12:08:47.249+0800 E STORAGE [initandlisten] WiredTiger (22) [1454213327:242370][13733:0x7fff72b68000], WT_SESSION.create: 'table:_mdb_catalog' cannot be used until all column groups are created: Invalid argument
2016-01-31T12:08:47.259+0800 I - [initandlisten] Fatal Assertion 28562
2016-01-31T12:08:47.259+0800 I - [initandlisten]
***aborting after fassert() failure
I have basically performed the following operations on terminal to install mongodb after looking through the docs and online tutorials:
joshuatan ~ $ brew update
joshuatan ~ $ brew install mongodb
joshuatan ~ $ sudo mkdir -p /data/db
joshuatan ~ $ whoami
joshuatan
joshuatan ~ $ sudo chown joshuatan /data/db
joshuatan ~ $ mongod
I have been searching around in google/stackoverflow but am not able to find any posts which have encountered a similar error.
Am i missing something? Would really appreciate any help/guidance...Thanks
The only thing that worked for me was (which was mac os)
rm -rf /tmp/mongodb-27017.soccd; cd /data/db; rm -rf *;
then just mongod to start it up
If you are on Catalina, like me, what seems to work is to create a properly placed data/db on System/Volumes/Data/data/db, with
sudo mkdir -p /System/Volumes/Data/data/db
sudo chown -R `id -un` /System/Volumes/Data/data/db
And, then, add that path to mongod.conf (located on /usr/local/etc/mongod.conf), replacing dbPath there:
...
storage:
dbPath: /System/Volumes/Data/data/db
...
Then, restart it. If you are using brew, do:
brew services restart mongodb-community
Source: https://zellwk.com/blog/install-mongodb/
I have been uninstalling and reinstalling Mongodb on Ubuntu 14.04 following the official documentation for few times now. However, I keep getting this:
2015-12-22T12:46:32.091+0000 I CONTROL ***** SERVER RESTARTED *****
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] MongoDB starting : pid=7039 port=27017 dbpath=/var/lib/mongodb 64-bit host=server-04
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] db version v3.0.8
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] git version: 83d8cc25e00e42856924d84e220fbe4a839e605d
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] build info: Linux ip-10-187-89-126 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] allocator: tcmalloc
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, syste$
2015-12-22T12:46:32.120+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-12-22T12:46:32.120+0000 I - [initandlisten] Fatal Assertion 28578
2015-12-22T12:46:32.120+0000 I - [initandlisten]
***aborting after fassert() failure
I am expecting to see: [initandlisten] waiting for connections on port <port> but can't see it. What can cause it?
remove everything from /tmp directory
sudo rm -rf /tmp/mongod*.sock
change the ownership of the db path and log path
chown -R mongodb:mongodb /var/lib/mongodb/
chown -R mongodb:mongodb /var/log/monogdb/
restart your mongo
sudo service mongod start