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