自带的标准 upstart 脚本适用于 MongoDB:
# Ubuntu upstart file at /etc/init/mongodb.conf
limit nofile 20000 20000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /var/lib/mongodb/
mkdir -p /var/log/mongodb/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf; fi
end script
如果我想运行第二个 mongod 实例,我认为我只需将 /etc/mongodb.conf
文件和 /etc/init/mongodb.conf
文件分别复制到 /etc/mongodb2.conf
和 /etc/init/mongodb2.conf
,并在第一个配置文件中更改标准端口。然后调整上面的脚本以使用新创建的 /etc/mongodb2.conf
启动。然后我只需说start mongodb2
,服务就会启动...但它会在启动后立即停止。我需要更改什么才能使两个进程都运行起来?
# Ubuntu upstart file at /etc/init/mongodb2.conf
limit nofile 20000 20000
kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
pre-start script
mkdir -p /var/lib/mongodb2/
mkdir -p /var/log/mongodb2/
end script
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb2.conf; fi
end script
--name
参数之前不允许我启动和停止多个mongod实例,谢谢! - thaddeusmt