Last active
March 16, 2017 22:53
-
-
Save ric2b/0e06e470cdaa355dc00a01b38adfd6aa to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
db=wells_US | |
collection=points | |
import_file=~/pocos-mapa-escala.geojson | |
executables_location=~/mongo | |
tools_location=~mongo-tools | |
dbs_location=~/dbs | |
logs_location=~/mongo_logs | |
router_addr=localhost | |
router_port=27017 | |
config_addr=localhost | |
config_port=27019 | |
shard1_addr=localhost | |
shard1_port=27018 | |
shard2_addr=localhost | |
shard2_port=27018 | |
case $1 in | |
"clean") | |
echo 'clearing old db folders' | |
rm -r $dbs_location | |
rm $logs_location/* | |
echo 'creating db folders' | |
mkdir -p $dbs_location/db_c1 $dbs_location/db_c2 $dbs_location/db_s1 $dbs_location/db_s2 | |
;; | |
"start") | |
case $2 in | |
"config") | |
echo 'starting the config server' | |
$executables_location/mongod --configsvr --replSet devcluster_cfg --dbpath $dbs_location/db_c1/ --port $config_port | |
;; | |
"shard1") | |
echo 'starting shard1' | |
$executables_location/mongod --shardsvr --replSet devcluster_sh1 --dbpath $dbs_location/db_s1 --port $shard1_port | |
;; | |
"shard2") | |
echo 'starting shard2' | |
$executables_location/mongod --shardsvr --replSet devcluster_sh2 --dbpath $dbs_location/db_s2 --port $shard2_port | |
;; | |
"s") | |
echo 'starting s server' | |
$executables_location/mongos --configdb devcluster_cfg/$config_addr:$config_port --port $router_port | |
;; | |
*) | |
echo 'no server name given to start' | |
;; | |
esac | |
;; | |
"initiate") | |
case $2 in | |
"config" | "ALL") | |
echo 'initiating the config server' | |
$executables_location/mongo --host $config_addr --port $config_port --eval " | |
rs.initiate( | |
{ | |
_id: 'devcluster_cfg', | |
configsvr: true, | |
members: [ | |
{ _id: 0, host: \"$config_addr:$config_port\"} | |
] | |
} | |
)" | |
;;& | |
"shard1" | "ALL") | |
echo 'initiating shard1' | |
$executables_location/mongo --host $shard1_addr --port $shard1_port --eval " | |
rs.initiate( | |
{ | |
_id: 'devcluster_sh1', | |
members: [ | |
{ _id: 0, host: \"$shard1_addr:$shard1_port\"} | |
] | |
} | |
)" | |
;;& | |
"shard2" | "ALL") | |
echo 'initiating shard2' | |
$executables_location/mongo --host $shard2_addr --port $shard2_port --eval " | |
rs.initiate( | |
{ | |
_id: 'devcluster_sh2', | |
members: [ | |
{ _id: 0, host: \"$shard2_addr:$shard2_port\"} | |
] | |
} | |
)" | |
;;& | |
"s" | "ALL") | |
echo 'initiating s' | |
if [ "$2" == "ALL" ]; then sleep 4; fi # wait for the others to initialize | |
$executables_location/mongo --host $router_addr --port $router_port --eval "sh.addShard(\"devcluster_sh1/$shard1_addr:$shard1_port\")" | |
$executables_location/mongo --host $router_addr --port $router_port --eval "sh.addShard(\"devcluster_sh2/$shard2_addr:$shard2_port\")" | |
;; | |
*) | |
echo 'no server name given for initiation' | |
;; | |
esac | |
;; | |
"loadDB") | |
echo "loading the $db db in" | |
$tools_location/bin/mongoimport --host $router_addr:$router_port --db $db -c $collection --file $import_file | |
;; | |
"shardDB") | |
echo "enabling sharding for the $db DB" | |
$executables_location/mongo --host $router_addr --port $router_port --eval "sh.enableSharding(\"$db\")" | |
case $2 in | |
"btree") | |
echo "creating index on the $db.$collection collection" | |
$executables_location/mongo --host $router_addr --port $router_port $db --eval "db.$collection.createIndex({_id: 1})" | |
echo "sharding the $db.$collection collection" | |
$executables_location/mongo --host $router_addr --port $router_port --eval "sh.shardCollection(\"$db.$collection\", {_id: 1})" | |
;; | |
"geo") | |
echo "creating index on the $db.$collection collection" | |
$executables_location/mongo --host $router_addr --port $router_port $db --eval "db.$collection.createIndex({\"geometry.coordinates\": \"2dsphere\"})" | |
# echo 'DISABLING THE BALANCER' | |
# $executables_location/mongo --host $router_addr --port $router_port --eval 'sh.stopBalancer()' | |
echo "sharding the $db.$collection collection" | |
$executables_location/mongo --host $router_addr --port $router_port --eval "sh.shardGeoCollection(\"$db.$collection\", {\"geometry.coordinates\": \"2dsphere\"})" | |
;; | |
*) | |
echo 'no mode given: btree or geo' | |
;; | |
esac | |
;; | |
"insertPoint") | |
echo "inserting MyPoint with coordinates: [$2,$3]" | |
$executables_location/mongo --host $router_addr --port $router_port $db --eval "db.$collection.insert({\"name\": \"MyPoint\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [$2,$3]}})" | |
echo "looking for \"MyPoint\" with coordinates: [$2,$3]" | |
$executables_location/mongo --host $router_addr --port $router_port $db --eval "db.$collection.find({\"geometry\": {\"type\": \"Point\", \"coordinates\": [$2,$3]}})" | |
;; | |
*) | |
echo 'no option chosen' | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Terminator shortcut arguments:
terminator -m -l mongo_cluster_layout
Terminator config (
~/.config/terminator/config
) :