Last active
November 20, 2022 12:31
-
-
Save crapthings/71fb6156a8e9b31a2fa7946ebd7c4edc to your computer and use it in GitHub Desktop.
Revisions
-
crapthings revised this gist
Dec 11, 2019 . 1 changed file with 9 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,36 +4,36 @@ services: hostname: mongo1 container_name: localmongo1 image: mongo restart: always expose: - 27017 ports: - 27017:27017 command: '--quiet --bind_ip_all --replSet rs0' volumes: - /data/db/mongo:/data/db mongo2: hostname: mongo2 container_name: localmongo2 image: mongo restart: always expose: - 27017 ports: - 27018:27017 command: '--quiet --bind_ip_all --replSet rs0' mongo3: hostname: mongo3 container_name: localmongo3 image: mongo restart: always expose: - 27017 ports: - 27019:27017 command: '--quiet --bind_ip_all --replSet rs0' rsinit: build: @@ -44,3 +44,4 @@ services: - mongo2 - mongo3 entrypoint: ["sh", "-c", "rs.sh"]
-
crapthings revised this gist
Jul 5, 2019 . 2 changed files with 12 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,4 +39,8 @@ services: build: context: . dockerfile: rsinit depends_on: - mongo1 - mongo2 - mongo3 entrypoint: ["sh", "-c", "rs.sh"] This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ #!/bin/bash echo "prepare rs initiating" check_db_status() { mongo1=$(mongo --host mongo1 --port 27017 --eval "db.stats().ok" | tail -n1 | grep -E '(^|\s)1($|\s)') mongo2=$(mongo --host mongo2 --port 27017 --eval "db.stats().ok" | tail -n1 | grep -E '(^|\s)1($|\s)') mongo3=$(mongo --host mongo3 --port 27017 --eval "db.stats().ok" | tail -n1 | grep -E '(^|\s)1($|\s)') if [[ $mongo1 == 1 ]] && [[ $mongo2 == 1 ]] && [[ $mongo3 == 1 ]]; then init_rs else @@ -13,7 +15,9 @@ check_db_status() { init_rs() { ret=$(mongo --host mongo1 --port 27017 --eval "rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'mongo1:27017' }, { _id: 1, host: 'mongo2:27017' }, { _id: 2, host: 'mongo3:27017' } ] })" > /dev/null 2>&1) } check_db_status > /dev/null 2>&1 echo "rs initiating finished" exit 0 -
crapthings revised this gist
Jul 5, 2019 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,6 +39,4 @@ services: build: context: . dockerfile: rsinit entrypoint: ["sh", "-c", "rs.sh"] -
crapthings revised this gist
Jul 5, 2019 . 1 changed file with 2 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -35,12 +35,10 @@ services: restart: always entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0"] rsinit: build: context: . dockerfile: rsinit environment: WAIT_HOSTS: mongo1:27017, mongo2:27017, mongo3:27017 entrypoint: ["sh", "-c", "rs.sh"] -
crapthings revised this gist
Jul 5, 2019 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ #!/bin/bash check_db_status() { mongo1=$(mongo --host mongo1 --port 27017 --eval "db.stats().ok" | tail -1 | grep -E '(^|\s)1($|\s)') mongo2=$(mongo --host mongo2 --port 27017 --eval "db.stats().ok" | tail -1 | grep -E '(^|\s)1($|\s)') mongo3=$(mongo --host mongo3 --port 27017 --eval "db.stats().ok" | tail -1 | grep -E '(^|\s)1($|\s)') if [[ $mongo1 == 1 ]] && [[ $mongo2 == 1 ]] && [[ $mongo3 == 1 ]]; then init_rs else -
crapthings created this gist
Jul 5, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ version: '3' services: mongo1: hostname: mongo1 container_name: localmongo1 image: mongo expose: - 27017 ports: - 27017:27017 restart: always entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0"] # volumes: # - /data/db/mongotest:/data/db # This is where your volume will persist. e.g. VOLUME-DIR = ./volumes/mongodb mongo2: hostname: mongo2 container_name: localmongo2 image: mongo expose: - 27017 ports: - 27018:27017 restart: always entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0"] mongo3: hostname: mongo3 container_name: localmongo3 image: mongo expose: - 27017 ports: - 27019:27017 restart: always entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0"] mongo4: hostname: mongo4 container_name: localmongo4 build: context: . dockerfile: rsinit environment: WAIT_HOSTS: mongo1:27017, mongo2:27017, mongo3:27017 entrypoint: ["sh", "-c", "rs.sh"] This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/bin/bash check_db_status() { mongo1=$(mongo --host mongo1 --port 27017 --eval "db.stats().ok" | tail -n1 | grep -E '(^|\s)1($|\s)') mongo2=$(mongo --host mongo2 --port 27017 --eval "db.stats().ok" | tail -n1 | grep -E '(^|\s)1($|\s)') mongo3=$(mongo --host mongo3 --port 27017 --eval "db.stats().ok" | tail -n1 | grep -E '(^|\s)1($|\s)') if [[ $mongo1 == 1 ]] && [[ $mongo2 == 1 ]] && [[ $mongo3 == 1 ]]; then init_rs else check_db_status fi } init_rs() { ret=$(mongo --host mongo1 --port 27017 --eval "rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'mongo1:27017' }, { _id: 1, host: 'mongo2:27017' }, { _id: 2, host: 'mongo3:27017' } ] })" > /dev/null 2>&1) exit 0 } check_db_status > /dev/null 2>&1 This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ FROM mongo ADD rs.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/rs.sh