Skip to content

Commit

Permalink
added install.sh for upstart
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 3, 2011
1 parent 1cba7aa commit af55517
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 3 deletions.
2 changes: 1 addition & 1 deletion basicsetup/linux/init.d/README
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Read install.sh
The script is simple you can modify it and bend it to your needs quickly.
I wrote it is intentionally in not a not DRY functions fashion
So it will by straight forward. I think you will be able fairly easily
reconstruct this script in to a script of your needs
reconstruct this script in to a script of your needs.



Expand Down
2 changes: 1 addition & 1 deletion basicsetup/linux/init.d/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# for example:
# web0 127.0.0.1
#
# 3. change hostname in files: (search and replace web0)
# 3. change hostname in files: (search and replace web0 with your local hostname)
# mongos
# install.sh
#
Expand Down
73 changes: 73 additions & 0 deletions basicsetup/linux/upstart/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Mongodb Quick Installation Script

1. change ip binding to your likening in files: , the ip can be several separated by comma
mongodbs1r1.conf
mongodbs1r2.conf
mongodbs1r3.conf
mongodbconfigdb.conf
mongodbconfigdb2.conf
mongodbconfigdb3.conf
2. validate your /etc/hosts file
that it contains your hostname as a name not localhost
for example:
web0 127.0.0.1

3. change hostname in files: (search and replace web0)
mongos.conf
install.sh

4. run install.sh
if you have made a mistake you can uninstall and install again

5 Credits
Created by Shimon Doodkin (http://doodkin.com)




Read install.sh
The script is simple you can modify it and bend it to your needs quickly.
I wrote it is intentionally in not a not DRY functions fashion
So it will by straight forward. I think you will be able fairly easily
reconstruct this script in to a script of your needs.



plan:

all hosted on 127.0.0.1 one shard "s1"

mongod servers replica set "s1": web0:27018,web0:27020,web0:27021
config servers: web0:27019,web0:27119,web0:27219
mongos router: web0:27017

please note: this script doesn't configure how to shard a database
if you need it later you can do it yourself



snippets:

stop mongos
stop mongodbs1r1
stop mongodbs1r2
stop mongodbs1r3
stop mongodbconfigdb
stop mongodbconfigdb2
stop mongodbconfigdb3

start mongodbs1r1
start mongodbs1r2
start mongodbs1r3
start mongodbconfigdb
start mongodbconfigdb2
start mongodbconfigdb3
start mongos



Contribute to:
https://github.com/shimondoodkin/mongodb.co.il/tree/master/basicsetup/

Israeli MongoDB website
http://mongodb.co.il
277 changes: 277 additions & 0 deletions basicsetup/linux/upstart/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
#!/bin/sh
##################################################
# Contribute to: https://github.com/shimondoodkin/mongodb.co.il/tree/master/basicsetup/
#
# Mongodb Quick Installation Script
#
# 1. change ip binding to your likening if required.
# the ip can be several ips separated by comma
# in files:
# mongodbs1r1
# mongodbs1r2
# mongodbs1r3
# mongodbconfigdb
# mongodbconfigdb2
# mongodbconfigdb3
# 2. validate your /etc/hosts file
# that it contains your hostname as a name not localhost
# for example:
# web0 127.0.0.1
#
# 3. change hostname in files: (search and replace web0 with your local hostname)
# mongos
# install.sh
#
# 4. run install.sh
# if you have made a mistake you can uninstall and install again
#
# 5 Credits
# Created by Shimon Doodkin (http://doodkin.com)
#

DO_INSTALL=0

echo "What do you wish to do?"
select yn in "Uninstall" "Install"; do
case $yn in
Uninstall ) DO_INSTALL=1 break;;
Install ) DO_INSTALL=2 break;;
esac
done

##################################################
# installation steps
if [ $DO_INSTALL = 2 ] ; then

echo "copy upstart scripts to to /etc/init/";
cp -i mongodbs1r1.conf mongodbs1r2.conf mongodbs1r3.conf mongodbconfigdb.conf mongodbconfigdb2.conf mongodbconfigdb3.conf mongos.conf /etc/init/

echo "remove current mongodb from autostarting on boot ...";
stop mongodb
mv /etc/init/mongodb.conf /etc/init/mongodb.conf.disabled


## the order of installation is importent,
## first setup a replica set, with all the host names the same
## then start config servers, all together.
## then start mongos (never start mongos before all config servers are running) // config servers must _all_ be empty or set up from data of a valid config server
## then add the shrad

echo "start replica set members ...";


#initiate replica set

#start
start mongodbs1r1

#status
if [ $(mongo web0:27018 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server s1r1 is not ok";
echo " -- contents of /var/log/mongodb/mongodb.s1r1.log -- ";
cat /var/log/mongodb/mongodb.s1r1.log
echo " -- end of /var/log/mongodb/mongodb.s1r1.log -- ";
exit 1;
fi

#start
start mongodbs1r2

#status
if [ $(mongo web0:27020 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server s1r2 is not ok";
echo " -- contents of /var/log/mongodb/mongodb.s1r2.log -- ";
cat /var/log/mongodb/mongodb.s1r2.log
echo " -- end of /var/log/mongodb/mongodb.s1r2.log -- ";
exit 1;
fi

#start
start mongodbs1r3

#status
if [ $(mongo web0:27021 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server s1r3 is not ok";
echo " -- contents of /var/log/mongodb/mongodb.s1r3.log -- ";
cat /var/log/mongodb/mongodb.s1r3.log
echo " -- end of /var/log/mongodb/mongodb.s1r3.log -- ";
exit 1;
fi

echo "initiate replica set, can take about 60 seconds"

#connect to replica member

CODE="rs.initiate({_id : 's1',members : [\
{_id : 0, host : 'web0:27018'},\
{_id : 1, host : 'web0:27020'},\
{_id : 2, host : 'web0:27021', arbiterOnly:true }\
]}).errmsg"
mongo web0:27018/admin --eval "$CODE"

MONGO_ERROR=$?
if [ $MONGO_ERROR != 0 ] ; then
echo -e " \nERROR: initiating replica set. \n\
It is probably it is a syntax error \n\
Here is your code:\n"
echo "$CODE"
exit 1;
fi

if [ $(mongo web0:27018/admin --quiet --eval "rs.status().startupStatus;") = 3 ] ; then
echo -e " ^ \n\
ERROR: initiating replica set. \n\
at this point the replica set had to be already initiated. \n\
for some reason your code did not initiated the replica set. \n\
Here is your code:\n"
echo "$CODE"
exit 1;
fi

echo "waiting until replica set is ready";
SEC=0;
while true ; do
sleep 5;
echo "$SEC seconds passed. still waiting... ";
SEC=`expr $SEC + 5`;
STATUS=`mongo web0:27018/admin --quiet --eval "rs.status().ok;"`
if [ $STATUS = 1 ] ; then
echo "replica set is ready"; break;
fi
if [ $SEC -gt 300 ] ; then
echo "ERROR: replica set is not getting ready - timeout";
exit 1;
fi
done;

#if [ $(mongo web0:27018/admin --quiet --eval "db.serverStatus().ok;") = 1 ] ; then echo "server 1 is ok"; else echo "server 1 is not ok"; fi
#if [ $(mongo web0:27018/admin --quiet --eval "rs.status().ok;") = 1 ] ; then echo "server 1 replication is ok"; fi

echo "start config databases"

#initiate shards config

#start
start mongodbconfigdb

#status
if [ $(mongo web0:27019 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server configdb is not ok";
echo " -- contents of /var/log/mongodb/mongodb.configdb.log -- ";
cat /var/log/mongodb/mongodb.configdb.log
echo " -- end of /var/log/mongodb/mongodb.configdb.log -- ";
exit 1;
fi

#start
start mongodbconfigdb2

#status
if [ $(mongo web0:27119 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server configdb2 is not ok";
echo " -- contents of /var/log/mongodb/mongodb.configdb2.log -- ";
cat /var/log/mongodb/mongodb.configdb2.log
echo " -- end of /var/log/mongodb/mongodb.configdb2.log -- ";
exit 1;
fi

#start
start mongodbconfigdb3

#status
if [ $(mongo web0:27219 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server configdb3 is not ok";
echo " -- contents of /var/log/mongodb/mongodb.configdb3.log -- ";
cat /var/log/mongodb/mongodb.configdb3.log
echo " -- end of /var/log/mongodb/mongodb.configdb3.log -- ";
exit 1;
fi

echo "start mongos"

start mongos

#status mongos
if [ $(mongo web0:27017 --quiet --eval "db.serverStatus().ok;") != 1 ] ; then
echo "server configdb3 is not ok";
echo " -- contents of /var/log/mongodb/mongodb.configdb3.log -- ";
cat /var/log/mongodb/mongodb.configdb3.log
echo " -- end of /var/log/mongodb/mongodb.configdb3.log -- ";
exit 1;
fi

echo "set up shrading"

#connect to mongos
# add replica set s1 as a shrad to config servers through mongos
# do not add arbiters they are passive members - you will get an error.
mongo web0:27017/admin --eval "db.runCommand( { addshard : 's1/web0:27018,web0:27020' } ).errmsg"
MONGO_ERROR=$?
if [ $MONGO_ERROR != 0 ] ; then
echo -e " ^ \n\
mongos ERROR: adding replica set as a shrad to config servers. \n\
debug this , try running mongo manualy and execute the addshard command"
exit 1;
fi

echo installation complete. type mongo to see if everything is working
echo in the log lines like \"Wed May 25 00:36:02 [conn14] getmore local.oplog.rs cid:265112... bytes:20 nreturned:0 3979ms\" are normal. it is long pooling pings from replica slaves to master

fi




###########################################
## uninstall


if [ $DO_INSTALL = 1 ] ; then


echo "stop services"
#stop
stop mongos
stop mongodbconfigdb
stop mongodbconfigdb2
stop mongodbconfigdb3
stop mongodbs1r1
stop mongodbs1r2
stop mongodbs1r3

echo delete service scripts
rm /etc/init/mongos.conf
rm /etc/init/mongodbconfigdb.conf
rm /etc/init/mongodbconfigdb2.conf
rm /etc/init/mongodbconfigdb3.conf
rm /etc/init/mongodbs1r1.conf
rm /etc/init/mongodbs1r2.conf
rm /etc/init/mongodbs1r3.conf

echo delete logs
#rm logs
rm /var/log/mongodb/mongodb.s1r1.log
rm /var/log/mongodb/mongodb.s1r2.log
rm /var/log/mongodb/mongodb.s1r3.log
rm /var/log/mongodb/mongodb.configdb.log
rm /var/log/mongodb/mongodb.configdb2.log
rm /var/log/mongodb/mongodb.configdb3.log
rm /var/log/mongodb/mongos.log

# delete all configdbs in case of wrong startup _first_ time !!!only during setup!!!
rm -r /var/lib/mongodb/configdb
rm -r /var/lib/mongodb/configdb2
rm -r /var/lib/mongodb/configdb3
rm -r /var/lib/mongodb/s1r1
rm -r /var/lib/mongodb/s1r2
rm -r /var/lib/mongodb/s1r3


echo bring back the default mongodb. make it start on boot and and start it.
mv /etc/init/mongodb.conf.disabled /etc/init/mongodb.conf
start mongodb

echo uninstall finished

fi

2 changes: 1 addition & 1 deletion basicsetup/linux/upstart/mongos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ 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 sudo -u mongodb /usr/bin/mongos --configdb www0:27019,www0:27119,www0:27219 --bind_ip 127.0.0.1 --port 27017 --logpath /var/log/mongodb/mongos.log; fi
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec sudo -u mongodb /usr/bin/mongos --configdb web0:27019,web0:27119,web0:27219 --bind_ip 127.0.0.1 --port 27017 --logpath /var/log/mongodb/mongos.log; fi
end script

0 comments on commit af55517

Please sign in to comment.