Skip to content

Instantly share code, notes, and snippets.

@ric2b
Last active March 16, 2017 22:53
Show Gist options
  • Save ric2b/0e06e470cdaa355dc00a01b38adfd6aa to your computer and use it in GitHub Desktop.
Save ric2b/0e06e470cdaa355dc00a01b38adfd6aa to your computer and use it in GitHub Desktop.
#!/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
@ric2b
Copy link
Author

ric2b commented Jan 12, 2017

Terminator shortcut arguments: terminator -m -l mongo_cluster_layout

Terminator config (~/.config/terminator/config) :

[global_config]
  suppress_multiple_term_dialog = True
[keybindings]
[layouts]
  [[default]]
    [[[child1]]]
      command = ""
      parent = window0
      profile = default
      type = Terminal
    [[[window0]]]
      parent = ""
      type = Window
  [[mongo_cluster_layout]]
    [[[child0]]]
      fullscreen = False
      last_active_term = 716f42bf-c3c6-47e4-b1dd-991446946ccc
      last_active_window = True
      maximised = True
      order = 0
      parent = ""
      position = 65:24
      size = 1855, 1056
      title = ricardo@ricardo-virtual-machine: ~
      type = Window
    [[[child1]]]
      order = 0
      parent = child0
      position = 526
      ratio = 0.500946969697
      type = VPaned
    [[[child2]]]
      order = 0
      parent = child1
      position = 924
      ratio = 0.499730458221
      type = HPaned
    [[[child5]]]
      order = 1
      parent = child1
      position = 258
      ratio = 0.498091603053
      type = VPaned
    [[[child6]]]
      order = 0
      parent = child5
      position = 925
      ratio = 0.500269541779
      type = HPaned
    [[[child9]]]
      order = 1
      parent = child5
      position = 925
      ratio = 0.500269541779
      type = HPaned
    [[[terminal10]]]
      command = echo '5';sleep 0.5; ~/mongo/mongod --shardsvr --replSet devcluster_sh1 --dbpath ~/dbs/db_s1 --port 27000; bash
      order = 0
      parent = child9
      profile = default
      type = Terminal
      uuid = 4c0ca63b-ddb4-47b4-8afc-cee12515b44f
    [[[terminal11]]]
      command = echo '6';sleep 0.5; ~/mongo/mongod --shardsvr --replSet devcluster_sh2 --dbpath ~/dbs/db_s2 --port 27001;bash
      order = 1
      parent = child9
      profile = default
      type = Terminal
      uuid = 20830925-a1bf-4a7f-8436-0b2cec273c23
    [[[terminal3]]]
      command = echo '1';./setup_cluster.sh clean;sleep 2; ./setup_cluster.sh initiate ALL; sleep 2; echo 'READY'; bash
      order = 0
      parent = child2
      profile = default
      type = Terminal
      uuid = 716f42bf-c3c6-47e4-b1dd-991446946ccc
    [[[terminal4]]]
      command = echo '2'; bash
      order = 1
      parent = child2
      profile = default
      type = Terminal
      uuid = 6f522fd3-6e0f-4931-9c6f-2daa08edf87c
    [[[terminal7]]]
      command = echo '3'; sleep 0.5; ~/mongo/mongod --configsvr --replSet devcluster_cfg --dbpath ~/dbs/db_c1/ --port 27010; bash
      order = 0
      parent = child6
      profile = default
      type = Terminal
      uuid = cef068b8-d3f8-410c-bec8-68af5a2e0951
    [[[terminal8]]]
      command = echo '4';sleep 0.5; ~/mongo/mongos --configdb devcluster_cfg/localhost:27010 --port 27020; bash
      order = 1
      parent = child6
      profile = default
      type = Terminal
      uuid = d6687a41-f200-494f-9405-e0b23633eb20
[plugins]
[profiles]
  [[default]]
    background_image = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment