1. 程式人生 > >mongdb 終端關閉後,服務也退出關閉的問題解決

mongdb 終端關閉後,服務也退出關閉的問題解決

昨天發現系統宕機了,查了下原因是mongodb服務停了,看了下日誌:
1
2017-10-18T18:09:59.181+0800 I CONTROL  [signalProcessingThread] got signal 1 (Hangup), will terminate after current cmd ends
2017-10-18T18:09:59.181+0800 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
2017-10-18T18:09:59.225+0800 I CONTROL  [signalProcessingThread] now exiting
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] closing listening socket: 6
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] closing listening socket: 7
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
2017-10-18T18:09:59.226+0800 I NETWORK  [signalProcessingThread] shutdown: going to close sockets...
2017-10-18T18:09:59.226+0800 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
2017-10-18T18:09:59.226+0800 I NETWORK  [conn14] end connection 127.0.0.1:37191 (3 connections now open)
2017-10-18T18:09:59.227+0800 I NETWORK  [conn13] end connection 127.0.0.1:37190 (3 connections now open)
2017-10-18T18:09:59.227+0800 I NETWORK  [conn12] end connection 127.0.0.1:37189 (3 connections now open)
2017-10-18T18:09:59.227+0800 I NETWORK  [conn11] end connection 127.0.0.1:37188 (3 connections now open)
2017-10-18T18:09:59.258+0800 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
2017-10-18T18:09:59.258+0800 I CONTROL  [signalProcessingThread] dbexit:  rc: 0
重新起mongodb的服務(命令:nohup /home/mongodb-linux-x86_64-rhel62-3.2.3/bin/mongod -dbpath /home/mongodb &),系統又重新正常運行了。關閉Xshell之後系統又宕了。

查了下資料,原因是直接關閉Xshell視窗之後,linux認為是異常退出,這個shell程序會收到SIGNUP訊號,然後給它所有的子程序傳送SIGHUP訊號。

但是在mongodb啟動命令中加-fork引數,會自動將其掛到init程序(pid為1)下啟動,如果不加的話ppid(父程序id)就是當前的shell程序,所以加上–fork問題就可以解決了。 
啟動命令:/home/mongodb-linux-x86_64-rhel62-3.2.3/bin/mongod --dbpath /home/mongodb --logpath=/home/mongodb/rs2.1.log --fork

參考:http://blog.csdn.net/shawyeok/article/details/46486683