aboutsummaryrefslogtreecommitdiffstats
path: root/priv/templates/bin
blob: 523b88dbbe5132730a192c0569765c2afff29872 (plain) (blame)
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
72
73
74
75
76
77
#!/bin/sh

set -e

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_NAME="{{ rel_name }}"
REL_VSN="{{ rel_vsn }}"
ERTS_VSN="{{ erts_vsn }}"
REL_DIR="$RELEASE_ROOT_DIR/releases/$REL_VSN"
ERL_OPTS="{{ erl_opts }}"

find_erts_dir() {
    __erts_dir="$RELEASE_ROOT_DIR/erts-$ERTS_VSN"
    if [ -d "$__erts_dir" ]; then
        ERTS_DIR="$__erts_dir";
        ROOTDIR="$RELEASE_ROOT_DIR"
    else
        __erl="$(which erl)"
        code="io:format(\"~s\", [code:root_dir()]), halt()."
        __erl_root="$("$__erl" -boot no_dot_erlang -noshell -eval "$code")"
        ERTS_DIR="$__erl_root/erts-$ERTS_VSN"
        ROOTDIR="$__erl_root"
    fi
}

find_sys_config() {
    __possible_sys="$REL_DIR/sys.config"
    if [ -f "$__possible_sys" ]; then
        SYS_CONFIG="$__possible_sys"
    else 
       if [ -L "$__possible_sys".orig ]; then
          mv "$__possible_sys".orig "$__possible_sys"  
          SYS_CONFIG="$__possible_sys"
       fi
    fi
}

find_vm_args() {
    __possible_vm_args="$REL_DIR/vm.args"
    if [ -f "$__possible_vm_args" ]; then
        VM_ARGS="$__possible_vm_args"
    else 
       if [ -L "$__possible_vm_args".orig ]; then
          mv "$__possible_vm_args".orig "$__possible_vm_args"  
          VM_ARGS="$__possible_vm_args"
       fi
    fi
}

find_erts_dir
find_sys_config
find_vm_args
export ROOTDIR="$RELEASE_ROOT_DIR"
export BINDIR="$ERTS_DIR/bin"
export EMU="beam"
export PROGNAME="erl"
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
ERTS_LIB_DIR="$ERTS_DIR/../lib"
[ -f "$REL_DIR/$REL_NAME.boot" ] && BOOTFILE="$REL_NAME" || BOOTFILE=start
cd "$ROOTDIR"

# Save extra arguments
ARGS="$@"

# Build arguments for erlexec
set -- "$ERL_OPTS"
[ "$SYS_CONFIG" ] && set -- "$@" -config "$SYS_CONFIG"
[ "$VM_ARGS" ] && set -- "$@" -args_file "$VM_ARGS"
set -- "$@" -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" -boot "$REL_DIR/$BOOTFILE" "$ARGS"

# Boot the release
$BINDIR/erlexec $@