Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2700  / 3 Years ago, wed, july 21, 2021, 7:46:03

I need help crafting a crontable entry that will make sure the MongoDB service (daemon) is running on a particular port and if it is not, start it. I want to set this up so that if MongoDB crashes, it is automatically restarted. I'd like to have the check occur every five minutes. I have done this for other server processes but those services automatically exit if they find the port they want to bind to is already in use. My concern as a MongoDB newbie is that I'll end up starting yet another instance of MongoDB every five minutes instead of making sure only one instance is loaded. For example, here is my crontable entry for a chatbot service I keep running:



0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd /home/[username]/ChatScript; ./LinuxChatscript32 2>/home/[username]/cronserver.log 


How can I create something similar for MongoDB?


More From » cron

 Answers
7
*/5 * * * * /bin/bash -c 'if ! pgrep mongod; then /usr/sbin/service mongodb start; fi'

[#30452] Thursday, July 22, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
torlim

Total Points: 408
Total Questions: 113
Total Answers: 110

Location: Estonia
Member since Wed, May 27, 2020
4 Years ago
;