Skip to content

Instantly share code, notes, and snippets.

@gerzhan
Forked from RichardBronosky/aws-userdata.sh
Created March 2, 2018 18:16
Show Gist options
  • Save gerzhan/49b168c49c268b10d82f1ad652d23e36 to your computer and use it in GitHub Desktop.
Save gerzhan/49b168c49c268b10d82f1ad652d23e36 to your computer and use it in GitHub Desktop.

Revisions

  1. @RichardBronosky RichardBronosky revised this gist Jan 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion replica_set_init.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # 1. Run this script with no arguements on every SECONDARY node in the replica set.
    # 2. Run this script on the PRIMARY node with a single argument of `-a` followed by pingable names for each secondary (zero or more).

    # cd /tmp; curl -LO https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/init_mongo_rs.sh
    # cd /tmp; curl -LO https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/replica_set_init.sh

    # Log commands to stdout
    set -o xtrace
  2. @RichardBronosky RichardBronosky revised this gist Jan 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    # cd /tmp; curl -LO https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/uat_mongodb_upgrade_from_prod.sh
    # cd /tmp; curl -LO https://gist.githubusercontent.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/uat_mongodb_upgrade_from_prod.sh

    # Log commands to stdout
    set -o xtrace
  3. @RichardBronosky RichardBronosky renamed this gist Jan 25, 2017. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions init_mongo_rs.sh → replica_set_init.sh
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,10 @@

    # Usage:
    # 1. Run this script with no arguements on every SECONDARY node in the replica set.
    # 2. Run this script on the PRIMARY node with a single argument of `-a` followed by one or more pingable names for each secondary.
    # 2. Run this script on the PRIMARY node with a single argument of `-a` followed by pingable names for each secondary (zero or more).

    # cd /tmp; curl -LO https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/init_mongo_rs.sh

    confirm(){
    [[ $REPLY =~ ^[yY]([eE][sS])?$ ]]
    }

    # Log commands to stdout
    set -o xtrace
    # Exit on error
  4. @RichardBronosky RichardBronosky revised this gist Jan 25, 2017. 1 changed file with 60 additions and 0 deletions.
    60 changes: 60 additions & 0 deletions init_mongo_rs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/bin/bash

    # Usage:
    # 1. Run this script with no arguements on every SECONDARY node in the replica set.
    # 2. Run this script on the PRIMARY node with a single argument of `-a` followed by one or more pingable names for each secondary.

    # cd /tmp; curl -LO https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/init_mongo_rs.sh

    confirm(){
    [[ $REPLY =~ ^[yY]([eE][sS])?$ ]]
    }

    # Log commands to stdout
    set -o xtrace
    # Exit on error
    set -o errexit
    # Exit on use of unset variables
    set -o nounset
    # Exit and report on pipe failure
    set -o pipefail

    # from: https://docs.mongodb.com/manual/tutorial/deploy-replica-set/

    # Update MongoDB config to support the replica set
    sudo cp /etc/mongod.conf /etc/mongod.rs-prod.conf
    sudo mv /etc/mongod.conf /etc/mongod.org.conf
    sudo ln -s /etc/mongod.rs-prod.conf /etc/mongod.conf
    sudo patch /etc/mongod.rs-prod.conf <<EOF
    --- /etc/mongod.conf 2017-01-22 20:37:38.628479600 +0000
    +++ /etc/mongod.rs-prod.conf 2017-01-22 21:00:28.430689201 +0000
    @@ -21,7 +21,7 @@
    # network interfaces
    net:
    port: 27017
    - bindIp: 127.0.0.1
    +# bindIp: 127.0.0.1
    #processManagement:
    @@ -30,7 +30,8 @@
    #operationProfiling:
    -#replication:
    +replication:
    + replSetName: rs-prod
    #sharding:
    EOF
    sudo systemctl restart mongod

    # "on one and only one member of the replica set" https://goo.gl/gS6Kw5
    if [[ ${1-} == '-a' ]]; then
    mongo -eval 'rs.initiate()'
    shift
    for node in $@; do
    mongo -eval "rs.add('$node')"
    done
    fi
  5. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -39,4 +39,5 @@ sudo docker stop some-mongo
    sudo docker rm some-mongo

    # Load upgraded data into latest version of MongoDB (WiredTiger storage engine will be used)
    mongorestore /data/db/dump
    mongorestore /data/db/dump
    sudo rm -rf /data
  6. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #!/bin/bash

    # cd /tmp; curl -LO https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/uat_mongodb_upgrade_from_prod.sh

    # Log commands to stdout
    set -o xtrace
    # Exit on error
  7. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 12 additions and 3 deletions.
    15 changes: 12 additions & 3 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,8 @@ set -o nounset
    # Exit and report on pipe failure
    set -o pipefail


    cd /data/db
    mongodump -h prodmongo11.ies
    mongodump -h prodmongo12.ies

    # Get major versions from https://hub.docker.com/r/library/mongo/tags/
    step=0
    @@ -21,11 +20,21 @@ for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:$major_version
    set +o errexit
    false; while [[ $? > 0 ]]; do
    sleep 0.5
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done
    set -o errexit
    if (( $step == 0 )); then
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    fi
    ((step += 1))
    done
    done

    # Finish up with docker
    sudo rm -rf /data/db/dump/*
    sudo docker exec -it some-mongo bash -c 'cd /data/db; mongodump'
    sudo docker stop some-mongo
    sudo docker rm some-mongo

    # Load upgraded data into latest version of MongoDB (WiredTiger storage engine will be used)
    mongorestore /data/db/dump
  8. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,8 @@ mongodump -h prodmongo11.ies
    # Get major versions from https://hub.docker.com/r/library/mongo/tags/
    step=0
    for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker stop some-mongo ||:
    sudo docker rm some-mongo ||:
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:$major_version
    set +o errexit
    false; while [[ $? > 0 ]]; do
    @@ -26,6 +28,4 @@ for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    fi
    ((step += 1))
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    done
    done
  9. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 2 changed files with 9 additions and 4 deletions.
    5 changes: 4 additions & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -43,4 +43,7 @@ for service in mongod; do
    systemctl enable $service
    systemctl start $service
    systemctl status $service
    done
    done

    # Reboot to make docker changes take effect
    reboot
    8 changes: 5 additions & 3 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -16,14 +16,16 @@ mongodump -h prodmongo11.ies
    # Get major versions from https://hub.docker.com/r/library/mongo/tags/
    step=0
    for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker stop some-mongo ||:
    sudo docker rm some-mongo ||:
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:$major_version
    set +o errexit
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done
    if (( step == 0 )); then
    set -o errexit
    if (( $step == 0 )); then
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    fi
    ((step += 1))
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    done
  10. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done
    if (( step == 0 ));
    if (( step == 0 )); then
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    fi
    ((step += 1))
  11. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 2 changed files with 19 additions and 4 deletions.
    2 changes: 1 addition & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ done
    usermod -aG docker ubuntu
    # create mongodb data dir
    mkdir -p /data/db/dump
    chown ubuntu /data/db/dump
    chown ubuntu:ubuntu /data/db/dump

    # Enable and start services
    for service in mongod; do
    21 changes: 18 additions & 3 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,29 @@
    sudo mkdir -p /data/db/dump
    #!/bin/bash

    # Log commands to stdout
    set -o xtrace
    # Exit on error
    set -o errexit
    # Exit on use of unset variables
    set -o nounset
    # Exit and report on pipe failure
    set -o pipefail


    cd /data/db
    chown ubuntu dump
    mongodump -h prodmongo11.ies

    # get major versions from https://hub.docker.com/r/library/mongo/tags/
    # Get major versions from https://hub.docker.com/r/library/mongo/tags/
    step=0
    for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker stop some-mongo ||:
    sudo docker rm some-mongo ||:
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:$major_version
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done
    if (( step == 0 ));
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    fi
    ((step += 1))
    done
  12. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@ cd /data/db
    chown ubuntu dump
    mongodump -h prodmongo11.ies

    # get major versions from https://hub.docker.com/r/library/mongo/tags/
    for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker stop some-mongo ||:
    sudo docker rm some-mongo ||:
  13. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 2 changed files with 7 additions and 29 deletions.
    File renamed without changes.
    36 changes: 7 additions & 29 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -3,33 +3,11 @@ cd /data/db
    chown ubuntu dump
    mongodump -h prodmongo11.ies

    # 2.6.12
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:2.6.12
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done

    # 3.0.14
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:3.0.14
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done

    # 3.2.11
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:3.2.11
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done

    # 3.4.1
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:3.4.1
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    for major_version in 2.6.12 3.0.14 3.2.11 3.4.1; do
    sudo docker stop some-mongo ||:
    sudo docker rm some-mongo ||:
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:$major_version
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done
    done
  14. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 2 changed files with 43 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -25,10 +25,17 @@ EOF
    # Install packages
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    apt-get update
    for package in docker.io mongodb-org; do
    for package in docker.io mongodb-org linux-image-extra-$(uname -r) linux-image-extra-virtual; do
    apt-get install -y $package
    done

    # Package specific actions
    # add user:ubuntu to group:docker
    usermod -aG docker ubuntu
    # create mongodb data dir
    mkdir -p /data/db/dump
    chown ubuntu /data/db/dump

    # Enable and start services
    for service in mongod; do
    systemctl status $service || true # will return code 3 the first time, but gives good log info
    35 changes: 35 additions & 0 deletions uat_mongodb_upgrade_from_prod.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    sudo mkdir -p /data/db/dump
    cd /data/db
    chown ubuntu dump
    mongodump -h prodmongo11.ies

    # 2.6.12
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:2.6.12
    sudo docker exec -it some-mongo mongorestore /data/db/dump
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done

    # 3.0.14
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:3.0.14
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done

    # 3.2.11
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:3.2.11
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done

    # 3.4.1
    sudo docker stop some-mongo
    sudo docker rm some-mongo
    sudo docker run --name some-mongo -v /data/db:/data/db -d mongo:3.4.1
    false; while [[ $? > 0 ]]; do
    sudo docker exec -it some-mongo mongo --eval 'printjson((new Mongo()).getDBNames())'
    done
  15. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ done

    # Enable and start services
    for service in mongod; do
    systemctl status $service
    systemctl status $service || true # will return code 3 the first time, but gives good log info
    systemctl unmask $service
    systemctl enable $service
    systemctl start $service
  16. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,9 @@ EOF
    # Install packages
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    apt-get update
    apt-get install -y docker.io
    apt-get install -y mongodb-org
    for package in docker.io mongodb-org; do
    apt-get install -y $package
    done

    # Enable and start services
    for service in mongod; do
  17. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ EOF
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    apt-get update
    apt-get install -y docker.io
    apt-get install -y mongodb-orgsystemctl status mongod
    apt-get install -y mongodb-org

    # Enable and start services
    for service in mongod; do
  18. @RichardBronosky RichardBronosky revised this gist Jan 22, 2017. 2 changed files with 28 additions and 10 deletions.
    31 changes: 21 additions & 10 deletions install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,38 @@
    #!/bin/bash

    # run as root/sudo

    # Log commands to stdout and vicariously /var/log/cloud-init-output.log
    set -o xtrace
    # Exit on error
    set -o errexit
    # Exit on use of unset variables
    set -o nounset
    # Exit and report on pipe failure
    set -o pipefail

    # If not running as root, rerun via sudo
    if [[ $EUID > 0 ]]; then
    exec sudo "$0" "$@"
    fi

    # Let apt know not to error due to lack of Dialog
    export DEBIAN_FRONTEND=noninteractive

    apt install -y docker.io
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    # Add Mongo repo to sources
    tee /etc/apt/sources.list.d/mongodb-org-3.4.list <<EOF
    deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse
    EOF

    # Install packages
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    apt-get update
    apt-get install -y mongodb-org
    systemctl status mongod
    systemctl unmask mongod
    systemctl enable mongod
    systemctl start mongod
    systemctl status mongod
    apt-get install -y docker.io
    apt-get install -y mongodb-orgsystemctl status mongod

    # Enable and start services
    for service in mongod; do
    systemctl status $service
    systemctl unmask $service
    systemctl enable $service
    systemctl start $service
    systemctl status $service
    done
    7 changes: 7 additions & 0 deletions userdata.sh
    Original file line number Diff line number Diff line change
    @@ -5,13 +5,20 @@ script="/tmp/userdata.sh"

    echo "Running userdata script as $(whoami) from $(pwd)"

    # Log commands to stdout and vicariously /var/log/cloud-init-output.log
    set -o xtrace
    # Exit on error
    set -o errexit
    # Exit on use of unset variables
    set -o nounset
    # Exit and report on pipe failure
    set -o pipefail

    # Fetch setup script
    curl -L "$url" > $script

    # Make setup script executable
    chmod +x $script

    # Execute setup script
    $script
  19. @RichardBronosky RichardBronosky revised this gist Jan 21, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion userdata.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    url="https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/install_mongo.sh"
    script="/tmp/userdata.sh"

    echo "Running userdata script as $(whoami)"
    echo "Running userdata script as $(whoami) from $(pwd)"

    set -o xtrace
    set -o errexit
  20. @RichardBronosky RichardBronosky revised this gist Jan 21, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,8 @@ deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3
    EOF
    apt-get update
    apt-get install -y mongodb-org
    systemctl unmask mongodb
    systemctl status mongod
    systemctl unmask mongod
    systemctl enable mongod
    systemctl start mongod
    systemctl status mongod
  21. @RichardBronosky RichardBronosky revised this gist Jan 21, 2017. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -7,12 +7,8 @@ set -o errexit
    set -o nounset
    set -o pipefail

    if [ $EUID != 0 ]; then
    sudo "$0" "$@"
    exit $?
    else
    echo "You must run this script as root!"
    exit 1
    if [[ $EUID > 0 ]]; then
    exec sudo "$0" "$@"
    fi

    export DEBIAN_FRONTEND=noninteractive
  22. @RichardBronosky RichardBronosky revised this gist Jan 21, 2017. 2 changed files with 36 additions and 6 deletions.
    25 changes: 19 additions & 6 deletions install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,27 @@
    #!/bin/bash

    # run as root/sudo

    set -o xtrace
    set -o errexit
    set -o nounset
    set -o pipefail

    sudo apt install -y docker.io
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list <<EOF
    if [ $EUID != 0 ]; then
    sudo "$0" "$@"
    exit $?
    else
    echo "You must run this script as root!"
    exit 1
    fi

    export DEBIAN_FRONTEND=noninteractive

    apt install -y docker.io
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    tee /etc/apt/sources.list.d/mongodb-org-3.4.list <<EOF
    deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse
    EOF
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    sudo systemctl unmask mongodb
    apt-get update
    apt-get install -y mongodb-org
    systemctl unmask mongodb
    17 changes: 17 additions & 0 deletions userdata.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/bash

    url="https://gist.github.com/RichardBronosky/2d04c7c2e9a5bea67cd9760a35415a3f/raw/install_mongo.sh"
    script="/tmp/userdata.sh"

    echo "Running userdata script as $(whoami)"

    set -o xtrace
    set -o errexit
    set -o nounset
    set -o pipefail

    curl -L "$url" > $script

    chmod +x $script

    $script
  23. @RichardBronosky RichardBronosky revised this gist Jan 20, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,9 @@
    #!/bin/bash

    set -o errexit
    set -o nounset
    set -o pipefail

    sudo apt install -y docker.io
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list <<EOF
  24. @RichardBronosky RichardBronosky revised this gist Jan 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    sudo apt install -y docker.io
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list <<EOF
    deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/3.4/multiverse
    deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse
    EOF
    sudo apt-get update
    sudo apt-get install -y mongodb-org
  25. @RichardBronosky RichardBronosky created this gist Jan 20, 2017.
    8 changes: 8 additions & 0 deletions install_mongo.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    sudo apt install -y docker.io
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list <<EOF
    deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/3.4/multiverse
    EOF
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    sudo systemctl unmask mongodb