aboutsummaryrefslogtreecommitdiff
path: root/docker/start.sh
blob: 64a971f6650506e23f323ce591d1554bfeffe339 (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
#!/bin/bash
set -e

# Environment
export EJABBERD_HTTPS=${EJABBERD_HTTPS:-'true'}
export EJABBERD_STARTTLS=${EJABBERD_STARTTLS:-'true'}
export EJABBERD_S2S_SSL=${EJABBERD_S2S_SSL:-'true'}

source "${EJABBERD_HOME}/docker/lib/base_config.sh"
source "${EJABBERD_HOME}/docker/lib/config.sh"
source "${EJABBERD_HOME}/docker/lib/base_functions.sh"
source "${EJABBERD_HOME}/docker/lib/functions.sh"


# discover hostname
readonly nodename=$(get_nodename)

# set erlang node to node name from get_nodename
if [[ "$ERLANG_NODE" == "nodename" ]]; then
    export ERLANG_NODE="ejabberd@${nodename}"
fi


run_scripts() {
    local run_script=$1
    local run_script_dir="${EJABBERD_HOME}/docker/${run_script}"

    log "Run ${run_script} scripts..."
    for script in ${run_script_dir}/*.sh ; do
        if [ -f ${script} -a -x ${script} ] ; then
            ${script}
        fi
    done
}


_trap() {
    run_scripts "stop"
    log "Stopping ejabberd..."
    $EJABBERDCTL stop
    $EJABBERDCTL stopped
    exit 0
}


# Catch signals and shutdown ejabberd
trap _trap SIGTERM SIGINT

# print logfiles to stdout
tail -F ${LOGDIR}/crash.log \
        ${LOGDIR}/error.log \
        ${LOGDIR}/erlang.log \
        ${LOGDIR}/ejabberd.log &

# start ejabberd
run_scripts "pre"
log "Starting ejabberd..."
$EJABBERDCTL start
$EJABBERDCTL started
log "Ejabberd started."
run_scripts "post"

# run forever
while true; do sleep 1; done

log "Ejabberd stopped."


exit 0