编辑:到目前为止,这似乎不是门戈·洛克正如其他人所建议的那样,当我手动清除每次运行/opt/databases/db目录的内容时。在

我有一个简单的脚本来检查mongod进程是否和apacheactivemq一样运行。如果它们都在运行,则脚本退出。否则,它将尝试启动一个或两个进程。在

但是,当前脚本经历了启动activemq和mongod的动作,但是由于某些原因,它们没有保持活动状态。有什么想法吗?在

我的代码如下所示:def checkMongo():

try:
client = pymongo.MongoClient("localhost:27017", serverSelectionTimeoutMS=5)
client.server_info()
return True
except pymongo.errors.ServerSelectionTimeoutError as err:
print err
return False
def checkActivemq():
args = ['/opt/activemq/bin/activemq', 'status']
try :
proc = subprocess.check_output(args)
print proc
if 'ActiveMQ is running (pid ' in proc:
return True
except subprocess.CalledProcessError as e:
return False
if checkMongo():
print "Mongod is running"
else:
print "Mongod not running. Attempting to start Mongod"
subprocess.Popen(["mongod", "--fork", "--logpath /opt/logs/mongod.log", "--dbpath=/opt/databases/db" ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
time.sleep(5)
print "Checking to see if mongod started"
if checkMongo():
print "Mongo successfully started."
else:
print "FATAL: Mongod unable to start. :("
exit
print "Now activating activemq"
if checkActivemq():
print "Woot activemq is running"
else:
print "Activemq is not running. Starting activemq"
subprocess.Popen(['/opt/activemq/bin/activemq', 'start'])
time.sleep(5)
if checkActivemq():
print "activemq started succesfully."
else:
print "FATAL: Activemq did not start succesfully"

接收的输出:

^{pr2}$