github.com/techend/deis@v1.0.1-0.20141111224634-e0eee0392b8a/builder/slugrunner/runner/init (about)

     1  #!/bin/bash
     2  set -eo pipefail
     3  
     4  ## Load slug from Bind Mount, URL or STDIN
     5  
     6  export HOME=/app
     7  mkdir -p $HOME
     8  
     9  if [[ $(ls -A $HOME) ]]; then
    10  	true
    11  elif [[ $SLUG_URL ]]; then
    12  	curl -s "$SLUG_URL" | tar -xzC $HOME
    13  	unset SLUG_URL
    14  else
    15  	cat | tar -xzC $HOME
    16  fi
    17  cd $HOME
    18  
    19  ## Load profile.d and release config
    20  
    21  shopt -s nullglob
    22  mkdir -p .profile.d
    23  if [[ -s .release ]]; then
    24  	ruby -e "require 'yaml';(YAML.load_file('.release')['config_vars'] || {}).each{|k,v| puts \"#{k}='#{v}'\"}" > .profile.d/config_vars
    25  fi
    26  for file in .profile.d/*; do
    27  	source $file
    28  done
    29  hash -r
    30  
    31  ## Inject "start" command to run processes defined in Procfile
    32  
    33  case "$1" in
    34  	start)
    35  		if [[ -f Procfile ]]; then
    36  			command="$(ruby -e "require 'yaml';puts YAML.load_file('Procfile')['$2']")"
    37  		else
    38  			command="$(ruby -e "require 'yaml';puts (YAML.load_file('.release')['default_process_types'] || {})['$2']")"
    39  		fi
    40  		;;
    41  
    42  	*)
    43  		command="$@"
    44  		;;
    45  esac
    46  
    47  ## Use sdutil to register with service discovery
    48  
    49  if [[ $SD_NAME && $PORT ]]; then
    50  	if [[ $SD_HOST ]]; then
    51  		runner="sdutil exec -h $SD_HOST -s $SD_NAME:$PORT bash -c"
    52  		unset SD_HOST
    53  	else
    54  		runner="sdutil exec -s $SD_NAME:$PORT bash -c"
    55  	fi
    56  	unset SD_NAME
    57  elif [[ $SD_ARGS ]]; then
    58  	runner="sdutil $SD_ARGS bash -c"
    59  	unset SD_ARGS
    60  else
    61  	runner="bash -c"
    62  fi
    63  
    64  ## Run!
    65  
    66  exec $runner "$command"