Skip to content

Instantly share code, notes, and snippets.

@consolewitch
Last active March 25, 2019 20:26
Show Gist options
  • Save consolewitch/bf2498e98f88491bd81b23e9f2e7c872 to your computer and use it in GitHub Desktop.
Save consolewitch/bf2498e98f88491bd81b23e9f2e7c872 to your computer and use it in GitHub Desktop.
A really stupid entrypoint script from the mongo docker container version 3.2.3
#!/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 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment