【发布时间】:2017-03-07 23:05:48
【问题描述】:
编辑:到目前为止,这似乎不是其他人建议的 mongod.lock 的问题,因为我每次运行都会清除 /opt/databases/db 目录的内容,手动。
我有一个简单的脚本来检查我的 mongod 进程以及 Apache Activemq 是否正在运行。如果它们都在运行,则脚本退出。否则,它将尝试启动一个或两个进程。
然而,目前脚本正在执行启动 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"
收到的输出:
Checking if mongod is up
localhost:27017: [Errno 111] Connection refused
Mongod not running. Attempting to start Mongod
Checking to see if mongod started
localhost:27017: [Errno 111] Connection refused
FATAL: Mongod unable to start :(
Now activating activemq
Activemq is not running. Starting activemq
INFO: Loading '/opt/apache-activemq-5.14.1//bin/env'
INFO: Using java '/usr/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/opt/apache-activemq-5.14.1//data/activemq.pid' (pid '39632')
FATAL: Activemq did not start succesfully
【问题讨论】:
-
This 也可能有帮助
-
我在 /opt/databases/db/ 中没有任何文件,因此不幸的是,这些都不适用。此外,当我从命令行运行时: mongod --fork --logpath /opt/logs/mongod.log --dbpath=/opt/databases/db mongod 启动得很好。有什么想法吗?
-
一个问题...你为什么使用
--fork? this 说linux init 脚本不喜欢--fork,你应该使用调用程序的能力来调用作为后台进程(即popen)。看来您正在后台进程中创建后台进程.. -
另外,others 似乎在您的 ip 表配置不正确时会出现此问题
-
@Aaron 的回答是正确的。再次感谢大家!
标签: python subprocess