Skip to content

Commit 2797dc4

Browse files
author
Bob Grabar
committed
DOCS-692 first draft complete
1 parent 159496e commit 2797dc4

File tree

1 file changed

+95
-76
lines changed

1 file changed

+95
-76
lines changed

source/administration/process-management.txt

Lines changed: 95 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ MongoDB runs as a standard program. You can start MongoDB from a command
88
line by issuing the :program:`mongod` command and specifying options.
99
Fora list of options, see :doc:`/reference/mongod`. MongoDB can also run
1010
as a Windows service. For details, see
11-
:ref:`tutorial-mongod-as-windows-service`.
11+
:ref:`tutorial-mongod-as-windows-service`. To install MongoDB, see
12+
:doc:`/installation`.
1213

1314
The following examples assume the directory containing the
1415
:program:`mongod` process is included in your system paths. The
@@ -35,13 +36,13 @@ To start MongoDB in default mode, issue the following command:
3536
Specify a Data Directory
3637
~~~~~~~~~~~~~~~~~~~~~~~~
3738

38-
To specify the directory where MongoDB stores data files, you must
39-
create the directory and set its permissions appropriately. MongoDB does
40-
not create the directory if the directory does not exist.
39+
When you specify a data directory, the directory must already exist. If
40+
it does not, create it and set its permissions appropriately.
4141

42-
You then use the ``--dbpath`` option when starting MongoDB. The
43-
following command starts :program:`mongod` and stores data in the
44-
``/var/lib/mongodb/`` directory:
42+
To specify a data directory when starting MongoDB, use the
43+
:option:`--dbpath <mongod --dbpath>` option. The following command
44+
starts :program:`mongod` and stores data in the ``/var/lib/mongodb/``
45+
directory:
4546

4647
.. code-block:: sh
4748

@@ -51,19 +52,17 @@ Specify a TCP Port
5152
~~~~~~~~~~~~~~~~~~
5253

5354
If you run several :program:`mongod` processes on a single machine, you
54-
must assign each a different port. Only one can listen on the default
55-
port of ``27017``.
55+
must assign each a different port to listen on for client connections.
56+
Only one can listen on the default port of ``27017``.
5657

57-
To specify the port that MongoDB listens on for client connections, use
58-
the ``--port`` option. The following command starts :program:`mongod`
59-
listening on port ``12345``:
58+
To specify the port, use the ``--port`` option. The following command
59+
starts :program:`mongod` listening on port ``12345``:
6060

6161
.. code-block:: sh
6262

6363
mongod --port 12345
6464

65-
It is highly recommended that you use the default port number whenever
66-
possible, to avoid any confusion.
65+
Use the default port number whenever possible, to avoid any confusion.
6766

6867
If you use the :option:`--configsvr <mongod --configsvr>` or
6968
:option:`--shardsvr <mongod --shardsvr>` options, those options select an
@@ -73,114 +72,134 @@ Run ``mongod`` as a Daemon
7372
~~~~~~~~~~~~~~~~~~~~~~~~~~
7473

7574
To fork the :program:`mongod` process *and* redirect its output to a log
76-
file, use the ``--fork`` and ``--logpath`` options. You must create the
77-
log path directory ahead of time; however not the log file. MongoDB will
78-
create the log file if it does not exist.
75+
file, use the :option:`--fork <mongod --fork>` and :option:`--logpath <mongod
76+
--logpath>` options. You must create the log directory ahead of time.
77+
However, you need not create the log file. MongoDB will create the log
78+
file if it does not exist.
7979

8080
The following command runs :program:`mongod` as a daemon and records log
8181
output to ``/var/log/mongodb.log``. The command also uses the
82-
``--logappend`` option to ensure that :program:`mongod` appends new
83-
entries to the end of the log file rather than overwriting the content
84-
when the process restarts:
82+
:option:`--logappend <mongod --logappend>` option to ensure that
83+
:program:`mongod` appends new entries to the end of the log file rather
84+
than overwriting the content when the process restarts:
8585

86-
--logappend
8786
.. code-block:: sh
8887

8988
mongod --fork --logpath /var/log/mongodb.log --logappend
9089

90+
Additional Configuration Options
91+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92+
93+
For an overview of common configurations and examples of best-practice
94+
configurations for common use cases, see
95+
:doc:`/administration/configuration`.
96+
9197
Stop ``mongod``
9298
---------------
9399

94-
If :program:`mongod` is running in the foreground, then to stop :program:`mongod` press ``Control+C``.
95-
MongoDB does a clean exit when all ongoing operations are complete and flushes and closes all data files.
100+
To stop a :program:`mongod` instance that is running in the foreground,
101+
press ``Control+C``. MongoDB stops when all ongoing operations are
102+
complete and does a clean exit, flushing and closing all data files.
103+
104+
To stop a :program:`mongod` instance running in the background or foreground,
105+
issue the :method:`shutdownServer() <db.shutdownServer()>` method. Use the following sequence:
106+
107+
1. To open the :program:`mongo` shell for a :program:`mongod` instance
108+
running on the default port of ``27017``, issue the following command:
109+
110+
.. code-block:: sh
111+
112+
mongo
113+
114+
#. To switch to the ``admin`` database and shutdown the :program:`mongod`
115+
instance, issue the following commands:
96116

97-
Send shutdownServer() message from the mongo shell
117+
.. code-block:: javascript
98118

99-
The shell can request that the server terminate.
119+
use admin
120+
db.shutdownServer()
100121

101-
$ ./mongo
102-
> use admin
103-
> db.shutdownServer()
122+
This command works only from ``localhost`` or if the user is
123+
authenticated.
104124

105-
This command only works from localhost or if one is authenticated.
125+
Alternately, you can shut down the :program:`mongod` instance:
106126

107-
From a driver (where the helper function may not exist), one can run the
108-
command
127+
- using the :option:`--shutdown` option
109128

110-
{ "shutdown" : 1 }
129+
- from a driver using the :dbcommand:`shutdown`. For details, see the
130+
:doc:`drivers documentation </applications/drivers>` for your driver.
111131

112-
If this server is the primary in a replica set, it will go through the
113-
following process (version 1.9.1+):
132+
``mongod`` Shutdown and Replica Sets
133+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114134

115-
Check how up-to-date the secondaries are
116-
----------------------------------------
135+
If the :program:`mongod` is the :term:`primary` in a :term:`replica
136+
set`, the :program:`mongod` will go through the following process:
117137

118-
If no secondary within 10 seconds of the primary, return that we won't
119-
shut down (optionally pass the timeoutSecs option to wait for a
120-
secondary to catch up.
138+
1. Check how up-to-date the :term:`secondaries <secondary>` are.
121139

122-
If there is a secondary within 10 seconds of the primary, the primary
123-
will step down and wait for the secondary to catch up.
140+
#. If no secondary is within 10 seconds of the primary,
141+
:program:`mongod` will return a message that it will not shut down.
142+
You can pass the the :dbcommand:`shutdown` command a ``timeoutSecs``
143+
argument to wait for a secondary to catch up.
124144

125-
After 60 seconds or once the secondary has caught up, the primary will
126-
shut down.
145+
#. If there is a secondary within 10 seconds of the primary, the primary
146+
will step down and wait for the secondary to catch up.
147+
148+
#. After 60 seconds or once the secondary has caught up, the primary
149+
will shut down.
127150

128151
If there is no up-to-date secondary and you want the primary to shut
129-
down, you can use ``force : true``:
152+
down, issue the :dbcommand:`shutdown` command with the ``force``
153+
argument, as show in the following command:
130154

131155
.. code-block:: javascript
132156

133157
db.adminCommand({shutdown : 1, force : true})
134158

135-
You can also specify timeoutSecs : N, which will keep checking the
136-
secondaries for N seconds if none are immediately up-to-date. If any of
137-
the secondaries catch up within N seconds, the primary will shut down.
138-
If no secondaries catch up, it will not shut down.
159+
To keep checking the secondaries for a specified number of seconds if
160+
none are immediately up-to-date, issue :dbcommand:`shutdown` with the
161+
``timeoutSecs`` argument. MongoDB will keep checking the secondaries for
162+
the specified number of seconds if none are immediately up-to-date. If
163+
any of the secondaries catch up within the allotted time, the primary
164+
will shut down. If no secondaries catch up, it will not shut down.
165+
166+
The following command issues :dbcommand:`shutdown` with ``timeoutSecs``
167+
set to ``5``:
139168

140169
.. code-block:: javascript
141170

142171
db.adminCommand({shutdown : 1, timeoutSecs : 5})
143172

144-
or
173+
Alternately you can use the ``timeoutSecs`` argument with the
174+
:method:`shutdownServer() <db.shutdownServer()>` method:
145175

146176
.. code-block:: javascript
147177

148178
db.shutdownServer({timeoutSecs : 5})
149179

150-
This generates output similar to the following:
151-
152-
.. code-block:: javascript
153-
154-
{
155-
"closest" : NumberLong(1307651781),
156-
"difference" : NumberLong(1307651808),
157-
"errmsg" : "no secondaries within 10 seconds of my optime",
158-
"ok" : 0
159-
}
160-
161-
Sending a Unix INT or TERM Signal
180+
Sending a UNIX INT or TERM Signal
162181
---------------------------------
163182

164-
You can cleanly stop :program:`mongod` using a SIGINT or SIGTERM signal on
165-
Unix-like systems. Either ^C, "kill -2 PID," or kill -15 PID will work.
183+
You can cleanly stop :program:`mongod` using a SIGINT or SIGTERM signal
184+
on UNIX-like systems. Either ``^C``, ``kill -2 PID``, or ``kill -15
185+
PID`` will work.
166186

167-
Sending a KILL signal kill -9 will probably cause damage if :program:`mongod` is
168-
not running with Journaling. (Journaling is on by default for 64 bit
169-
:program:`mongod`.) See also: repairDatabase command.)
187+
Sending ``kill -9`` will probably cause damage if :program:`mongod` is
188+
not running with :term:`journaling <journal>`.
170189

171-
After a hard crash, when not using --journal, MongoDB will say it was
172-
not shutdown cleanly, and ask you to do a repair of the database.
190+
To recover data if MongoDB does not shut down cleanly and if
191+
:term:`journaling <journal>` is disabled, see
192+
:doc:`/tutorial/recover-data-following-unexpected-shutdown`.
173193

174194
Memory Usage
175195
------------
176196

177-
MongoDB uses memory mapped files to access data, which results in large
178-
numbers being displayed in tools like top for the :program:`mongod` process. This
179-
is not a concern, and is normal when using memory-mapped files.
180-
Basically, the size of mapped data is shown in the virtual size
181-
parameter, and resident bytes shows how much data is being cached in
182-
RAM.
197+
MongoDB uses memory-mapped files to access data, which results in large
198+
numbers being displayed in tools like ``top`` for the :program:`mongod`
199+
process. This is not a concern and is normal when using memory-mapped
200+
files. The size of mapped data is shown in the virtual size parameter.
201+
Resident bytes shows how much data is being cached in RAM.
183202

184203
You can get a feel for the "inherent" memory footprint of MongoDB by
185-
starting it fresh, with no connections, with an empty /data/db directory
186-
and looking at the resident bytes.
204+
starting it fresh, with no connections, with an empty ``/data/db``
205+
directory and looking at the resident bytes.

0 commit comments

Comments
 (0)