Created
December 4, 2013 17:41
-
-
Save pior/7792074 to your computer and use it in GitHub Desktop.
Install a local MongoDB replicaset with the 10gen APT repo (upstart). http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start on runlevel [2345] | |
stop on runlevel [06] | |
pre-start script | |
start mongodb-node replset=rs_local_a port=27017 | |
start mongodb-node replset=rs_local_a port=27117 | |
start mongodb-node replset=rs_local_a port=27217 | |
sleep 3 | |
mongo localhost:27017 /etc/mongo-initiate-localrs.js | |
end script | |
post-stop script | |
stop mongodb-node replset=rs_local_a port=27017 | |
stop mongodb-node replset=rs_local_a port=27117 | |
stop mongodb-node replset=rs_local_a port=27217 | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance $replset-$port | |
respawn | |
respawn limit 3 15 | |
kill timeout 300 # wait 300s between SIGTERM and SIGKILL. | |
# http://www.mongodb.org/display/DOCS/Too+Many+Open+Files | |
# MongoDB has a hard limit of 20k connections | |
limit nofile 8192 8192 | |
pre-start script | |
mkdir -p /var/local/mongodb/mongodb-data-$replset-$port || true | |
mkdir -p /var/local/mongodb/mongodb-log-$replset-$port || true | |
chown mongodb -R /var/local/mongodb/mongodb-data-$replset-$port || true | |
chown mongodb -R /var/local/mongodb/mongodb-log-$replset-$port || true | |
end script | |
script | |
exec start-stop-daemon --start --quiet --chuid mongodb \ | |
--name mongodb-$replset-$port --exec /usr/bin/mongod -- \ | |
--replSet $replset --smallfiles --port $port --oplogSize 64 \ | |
--dbpath /var/local/mongodb/mongodb-data-$replset-$port \ | |
--logpath /var/local/mongodb/mongodb-log-$replset-$port/mongodb.log | |
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (rs.status()["ok"] == 0) { | |
sleep(15000); | |
if(rs.status()["ok"] == 0 && | |
rs.status()["startupStatus"] == 3) { | |
var host = db.serverStatus()["host"].split(":")[0]; | |
cfg = { _id: "rs_local_a", | |
members:[ | |
{_id:0,host: host+":27017"}, | |
{_id:1,host: host+":27117"}, | |
{_id:2,host: host+":27217"}, | |
] | |
}; | |
rs.initiate(cfg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment