Record a "weird" mongodb process exit event and mongodb process exit event
In shell, the mongo process is started through mongo args &. After logging out of shell and re-login, the mongo process is found to be gone. The following output is found in view logs:
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread]Got signal 1 (Hangup), will terminate after current cmd ends
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] now exiting
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] dbexit:
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] shutdown: going to close listening sockets...
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] closing listening socket: 8
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] closing listening socket: 10
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] removing socket file:/tmp/mongodb-27017.sock
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] shutdown: going to flush diaglog...
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] shutdown: going to close sockets...
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] shutdown: waiting for fs preallocator...
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] shutdown: lock for final commit...
2015-06-18T18: 39: 58.593 + 0800 [signalProcessingThread] shutdown: final commit...
2015-06-18T18: 39: 58.603 + 0800 [replslave] repl: AssertionException dbclient error communicating with server: 172.19.2.176: 27017
2015-06-18T18: 39: 58.615 + 0800 [signalProcessingThread] shutdown: closing all files...
2015-06-18T18: 39: 58.642 + 0800 [signalProcessingThread] closeAllFiles () finished
2015-06-18T18: 39: 58.642 + 0800 [signalProcessingThread] journalCleanup...
2015-06-18T18: 39: 58.642 + 0800 [signalProcessingThread] removeJournalFiles
2015-06-18T18: 39: 58.643 + 0800 [signalProcessingThread] shutdown: removing fs lock...
2015-06-18T18: 39: 58.643 + 0800 [signalProcessingThread] dbexit: really exiting now
You can see that other processes send Hangup information to mongo, just likekill -1 pid
But it can be confirmed that no one manually signals to the mongodb process. google later found this article
The reasons are as follows:
Bash resends a SIGHUP to all jobs if it has es a SIGHUP itself; this wowould include mongod.
Also, if you happen to have huponexit turned on, every job will receive a SIGHUP when bash exits.
Https://www.gnu.org/software/bash/manual/html_node/Signals.html
After logging in with shell, I started mongo and then exited the shell to directly close the window. linux considers this as an abnormal exit, so that the shell process will receive the SIGHUP signal, to ensure State consistency, send a SIGHUP signal to all its sub-processes. the exit command does not cause this problem, because linux considers this as a normal exit.
So how can we avoid this problem? Closing the window directly may be a habit of many people (bad habits). Therefore, we cannot require the linux administrator to always do this. It is because a person may make mistakes and should fundamentally solve this problem.
View the mongodb official documentation and you will find that mongo has a parameter such as-fork. When you use this parameter to start mongo, it is automatically mounted to the init process (pid is 1) for startup, if no ppid is added, the parent process id is the current shell process. Therefore, if the-fork problem is added, the problem is solved. Note that, all programs that need to run in the background need to pay attention to this situation and must be executed in a way similar to mongo-fork.
For more information about Linux signal and bash, follow these steps.Man bash