github.com/smintz/nomad@v0.8.3/dev/docker-clients/build/start.sh (about)

     1  #!/usr/local/bin/dumb-init /bin/sh
     2  # Script created following HashiCorp's model for Consul: 
     3  # https://github.com/hashicorp/docker-consul/blob/master/0.X/docker-entrypoint.sh
     4  # Comments in this file originate from the project above, simply replacing 'Consul' with 'Nomad'.
     5  set -e
     6  
     7  # Note above that we run dumb-init as PID 1 in order to reap zombie processes
     8  # as well as forward signals to all processes in its session. Normally, sh
     9  # wouldn't do either of these functions so we'd leak zombies as well as do
    10  # unclean termination of all our sub-processes.
    11  
    12  # NOMAD_DATA_DIR is exposed as a volume for possible persistent storage. The
    13  # NOMAD_CONFIG_DIR isn't exposed as a volume but you can compose additional
    14  # config files in there if you use this image as a base, or use NOMAD_LOCAL_CONFIG
    15  # below.
    16  NOMAD_DATA_DIR=/nomad/data
    17  NOMAD_CONFIG_DIR=/etc/nomad
    18  
    19  # You can also set the NOMAD_LOCAL_CONFIG environment variable to pass some
    20  # Nomad configuration JSON without having to bind any volumes.
    21  if [ -n "$NOMAD_LOCAL_CONFIG" ]; then
    22  	echo "$NOMAD_LOCAL_CONFIG" > "$NOMAD_CONFIG_DIR/local.json"
    23  fi
    24  
    25  # If the user is trying to run Nomad directly with some arguments, then
    26  # pass them to Nomad.
    27  if [ "${1:0:1}" = '-' ]; then
    28      set -- nomad "$@"
    29  fi
    30  
    31  # Look for Nomad subcommands.
    32  if [ "$1" = 'agent' ]; then
    33      shift
    34      set -- nomad agent \
    35          -data-dir="$NOMAD_DATA_DIR" \
    36          -config="$NOMAD_CONFIG_DIR" \
    37          "$@"
    38  elif [ "$1" = 'version' ]; then
    39      # This needs a special case because there's no help output.
    40      set -- nomad "$@"
    41  elif nomad --help "$1" 2>&1 | grep -q "nomad $1"; then
    42      # We can't use the return code to check for the existence of a subcommand, so
    43      # we have to use grep to look for a pattern in the help output.
    44      set -- nomad "$@"
    45  fi
    46  
    47  # If we are running Nomad, make sure it executes as the proper user.
    48  if [ "$1" = 'nomad' ]; then
    49      # If the data or config dirs are bind mounted then chown them.
    50      # Note: This checks for root ownership as that's the most common case.
    51      if [ "$(stat -c %u /nomad/data)" != "$(id -u root)" ]; then
    52          chown root:root /etc/nomad
    53      fi
    54  
    55      # If requested, set the capability to bind to privileged ports before
    56      # we drop to the non-root user. Note that this doesn't work with all
    57      # storage drivers (it won't work with AUFS).
    58      if [ ! -z ${NOMAD+x} ]; then
    59          setcap "cap_net_bind_service=+ep" /bin/nomad
    60      fi
    61  
    62      set -- gosu root "$@"
    63  fi
    64  
    65  exec "$@"