简体   繁体   English

如何在Ubuntu 16.04中自动重启Mongodb

[英]How to auto-restart Mongodb in Ubuntu 16.04

I can't figure out how to auto-restart mongodb on Ubuntu 16.04 in the event that it crashes due to memory-pressure. 我无法弄清楚如何在Ubuntu 16.04上因内存压力崩溃而自动重启mongodb。

I'm using supervisord for other scripts etc, but mongod is through systemctl and I'm not sure how that ties into it. 我正在使用supervisord用于其他脚本等,但mongod是通过systemctl而我不确定它是如何与它相关联的。

Figured it out: 弄清楚了:

  1. Edit your mongod service: sudo vim /lib/systemd/system/mongod.service 编辑你的mongod服务: sudo vim /lib/systemd/system/mongod.service
  2. Add Restart=always under service 添加Restart=alwaysservice
  3. Reload systemctl daemon: sudo systemctl daemon-reload 重新加载systemctl守护程序: sudo systemctl daemon-reload

Now whenever mongod gets killed. 现在每当mongod被杀。 It'll get respawned by systemctl. 它会被systemctl重生。

When you install mongoDB just run systemctl enable mongod.service on terminal. 当您安装mongoDB只需在终端上运行systemctl enable mongod.service

This will make your mongoDB service auto-start on every restart. 这将使您的mongoDB服务在每次重启时自动启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM