-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy patherlang-start
executable file
·71 lines (60 loc) · 1.9 KB
/
erlang-start
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
71
#!/usr/bin/env bash
set -euo pipefail
# uncomment to see all execution
#set -x
export RUN_DIR="/tmp/erllambda_rundir"
export VAR_DIR=${RUN_DIR}
$(mkdir -p "${RUN_DIR}/cachefs")
$(mkdir -p "${RUN_DIR}/checkpointfs")
$(mkdir -p "${RUN_DIR}/tmpfs")
$(mkdir -p "${RUN_DIR}/ramfs")
SCRIPT=$(readlink $0 || true)
if [ -z $SCRIPT ]; then
SCRIPT=$0
fi;
SCRIPT_DIR="$(cd `dirname "$SCRIPT"` && pwd -P)"
RELEASE_ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)"
REL_DIRS=(${RELEASE_ROOT_DIR}/releases/[0-9]*)
REL_DIR=${REL_DIRS[-1]}
ERTS_DIR=(${RELEASE_ROOT_DIR}/erts-*)
ERTS_LIB_DIR="${ERTS_DIR}/lib"
export NATIVELIB_DIR=${ERTS_LIB_DIR}
export REL_NAME="$(basename $SCRIPT)"
PROGNAME=appmod;
CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
replace_os_vars() {
awk '{
while(match($0,"[$]{[^}]*}")) {
var=substr($0,RSTART+2,RLENGTH -3)
gsub("[$]{"var"}",ENVIRON[var])
}
}1' < "$1" > "$2"
}
# perform environment variable substitution into run- files
VMARGS_SRC="${REL_DIR}/vm.args"
VMARGS_PATH="${RUN_DIR}/vm.args"
replace_os_vars ${VMARGS_SRC} ${VMARGS_PATH}
CONFIG_SRC="${REL_DIR}/sys.config"
CONFIG_PATH="${RUN_DIR}/sys.config"
replace_os_vars ${CONFIG_SRC} ${CONFIG_PATH}
export HOME="$RELEASE_ROOT_DIR"
export ROOTDIR="$RELEASE_ROOT_DIR"
export BINDIR="$ERTS_DIR/bin"
export EMU="beam"
export LD_LIBRARY_PATH="${ERTS_DIR}/lib:${LD_LIBRARY_PATH}"
# disable Erlang crash dumps and Linux core dumps
export ERL_CRASH_DUMP="/dev/null"
ulimit -c 0
# Store passed arguments since they will be erased by `set`
ARGS="$@"
set -- "$ERTS_DIR/bin/erlexec" -noshell -noinput -Bd \
-boot "$REL_DIR/$REL_NAME" \
-mode "$CODE_LOADING_MODE" \
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
-config "$CONFIG_PATH" \
-args_file "$VMARGS_PATH"
d=$(date '+%T.%6N')
arch=$(uname -m)
echo "Date: ${d} Root: $ROOTDIR Arch: ${arch} Exec: $@" -- ${1+$ARGS}
cd $ROOTDIR
exec "$@" -- ${1+$ARGS} 2>&1