Skip to content

Instantly share code, notes, and snippets.

@consolewitch
Last active March 25, 2019 20:26
Show Gist options
  • Select an option

  • Save consolewitch/bf2498e98f88491bd81b23e9f2e7c872 to your computer and use it in GitHub Desktop.

Select an option

Save consolewitch/bf2498e98f88491bd81b23e9f2e7c872 to your computer and use it in GitHub Desktop.

Revisions

  1. consolewitch revised this gist Mar 25, 2019. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions mongo-entrypoint.sh
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,26 @@
    #!/bin/bash
    set -e

    # if parameters that start with '-' were passed to the script via the CMD directive then concat them to the string 'mongod'
    # if parameters that start with '-' were passed to the script via the CMD directive then concat
    # them to the string 'mongod'
    if [ "${1:0:1}" = '-' ]; then
    set -- mongod "$@"
    fi

    # if the last conditional statement was triggered or if we're running without any parameters (ie, the parameter 'mongod' was passed in from +++the docker executor) AND we're running as root then do stuff. NOTE: if we're inside of recursion this won't fire
    # if the last conditional statement was triggered or if we're running without any parameters
    # (ie, the parameter 'mongod' was passed in from +++the docker executor) AND we're running as
    # root then do stuff. NOTE: if we're inside of recursion this won't fire
    if [ "$1" = 'mongod' -a "$(id -u)" = '0' ]; then
    #give the mongodb user ownership of its working dirs
    # give the mongodb user ownership of its working dirs
    chown -R mongodb /data/configdb /data/db
    #recurse into this script but run as the user mongodb (bash_source is a shortcut to the name of the script we're currently in)
    #gosu is an off-brand su command. ex: gosu <username> <executable> <arguments>
    # recurse into this script but run as the user mongodb (bash_source is a shortcut to
    # the name of the script we're currently in)
    # gosu is an off-brand su command. ex: gosu <username> <executable> <arguments>
    exec gosu mongodb "$BASH_SOURCE" "$@"
    fi

    #this is the final step where we preface the $@ string with numactl which handles memory usage. This will execute every time unless the +++parameters sent are something other than mongod or an argument.
    # this is the final step where we preface the $@ string with numactl which handles memory
    # usage. This will execute every time unless the parameters sent are something other than mongod or an argument.
    if [ "$1" = 'mongod' ]; then
    numa='numactl --interleave=all'
    if $numa true &> /dev/null; then
  2. consolewitch created this gist Mar 25, 2019.
    27 changes: 27 additions & 0 deletions mongo-entrypoint.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/bash
    set -e

    # if parameters that start with '-' were passed to the script via the CMD directive then concat them to the string 'mongod'
    if [ "${1:0:1}" = '-' ]; then
    set -- mongod "$@"
    fi

    # if the last conditional statement was triggered or if we're running without any parameters (ie, the parameter 'mongod' was passed in from +++the docker executor) AND we're running as root then do stuff. NOTE: if we're inside of recursion this won't fire
    if [ "$1" = 'mongod' -a "$(id -u)" = '0' ]; then
    #give the mongodb user ownership of its working dirs
    chown -R mongodb /data/configdb /data/db
    #recurse into this script but run as the user mongodb (bash_source is a shortcut to the name of the script we're currently in)
    #gosu is an off-brand su command. ex: gosu <username> <executable> <arguments>
    exec gosu mongodb "$BASH_SOURCE" "$@"
    fi

    #this is the final step where we preface the $@ string with numactl which handles memory usage. This will execute every time unless the +++parameters sent are something other than mongod or an argument.
    if [ "$1" = 'mongod' ]; then
    numa='numactl --interleave=all'
    if $numa true &> /dev/null; then
    set -- $numa "$@"
    fi
    fi

    #here we actually fire off whatever is in the $@ string.
    exec "$@"