aboutsummaryrefslogtreecommitdiff
path: root/docker/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'docker/scripts/lib')
-rw-r--r--docker/scripts/lib/base_config.sh53
-rw-r--r--docker/scripts/lib/base_functions.sh66
-rw-r--r--docker/scripts/lib/config.sh1
-rw-r--r--docker/scripts/lib/functions.sh1
4 files changed, 121 insertions, 0 deletions
diff --git a/docker/scripts/lib/base_config.sh b/docker/scripts/lib/base_config.sh
new file mode 100644
index 000000000..a856fe785
--- /dev/null
+++ b/docker/scripts/lib/base_config.sh
@@ -0,0 +1,53 @@
+readonly HOSTIP=$(hostname -i)
+readonly HOSTNAME=$(hostname -f)
+readonly DOMAINNAME=$(hostname -d)
+
+readonly ERLANGCOOKIEFILE="${EJABBERD_HOME}/.erlang.cookie"
+readonly EJABBERDCTL="/sbin/ejabberdctl"
+readonly CONFIGFILE="${EJABBERD_HOME}/conf/ejabberd.yml"
+readonly CONFIGTEMPLATE="${EJABBERD_HOME}/conf/ejabberd.yml.tpl"
+readonly CTLCONFIGFILE="${EJABBERD_HOME}/conf/ejabberdctl.cfg"
+readonly CTLCONFIGTEMPLATE="${EJABBERD_HOME}/conf/ejabberdctl.cfg.tpl"
+readonly SSLCERTDIR="${EJABBERD_HOME}/ssl"
+readonly SSLCERTHOST="${SSLCERTDIR}/host.pem"
+readonly SSLDHPARAM="${SSLCERTDIR}/dh.pem"
+readonly LOGDIR="/var/log/ejabberd"
+readonly FIRST_START_DONE_FILE="/${EJABBERD_HOME}/first-start-done"
+readonly CLUSTER_NODE_FILE="/${EJABBERD_HOME}/cluster-done"
+
+readonly PYTHON_JINJA2="import os;
+import sys;
+import jinja2;
+sys.stdout.write(
+ jinja2.Template
+ (sys.stdin.read()
+ ).render(env=os.environ))"
+
+# backward compatibility environment variables
+set +e
+
+[[ -n $EJABBERD_ADMIN ]] \
+ && export EJABBERD_ADMINS=${EJABBERD_ADMIN}
+
+[[ -n $AUTH_METHOD ]] \
+ && export EJABBERD_AUTH_METHOD=${AUTH_METHOD}
+
+[[ -n $SKIP_MODULES_UPDATE ]] \
+ && export EJABBERD_SKIP_MODULES_UPDATE=${SKIP_MODULES_UPDATE}
+
+[[ -n $ERL_OPTIONS ]] \
+ && export ERLANG_OPTIONS=${ERL_OPTIONS}
+
+[[ -n $SSLCERT_HOST ]] \
+ && export EJABBERD_SSLCERT_HOST=${SSLCERT_HOST}
+
+[[ -n $SSLCERT_EXAMPLE_COM ]] \
+ && export EJABBERD_SSLCERT_EXAMPLE_COM=${SSLCERT_EXAMPLE_COM}
+
+[[ -n $LOGLEVEL ]] \
+ && export EJABBERD_LOGLEVEL=${LOGLEVEL}
+
+[[ -n $EJABBERD_WEB_ADMIN_SSL ]] \
+ && export EJABBERD_HTTPS=${EJABBERD_WEB_ADMIN_SSL}
+
+set -e
diff --git a/docker/scripts/lib/base_functions.sh b/docker/scripts/lib/base_functions.sh
new file mode 100644
index 000000000..daadd1f68
--- /dev/null
+++ b/docker/scripts/lib/base_functions.sh
@@ -0,0 +1,66 @@
+is_set() {
+ local var=$1
+
+ [[ -n $var ]]
+}
+
+
+is_zero() {
+ local var=$1
+
+ [[ -z $var ]]
+}
+
+
+file_exist() {
+ local file=$1
+
+ [[ -e $file ]]
+}
+
+
+is_true() {
+ local var=${1,,}
+ local choices=("yes" "1" "y" "true")
+ for ((i=0;i < ${#choices[@]};i++)) {
+ [[ "${choices[i]}" == $var ]] && return 0
+ }
+ return 1
+}
+
+
+# overwrite this function to get hostname from other sources
+# like dns or etcd
+get_nodename() {
+ echo ${HOSTNAME}
+}
+
+
+join_cluster() {
+ local cluster_node=$1
+
+ is_zero ${cluster_node} \
+ && exit 0
+
+ echo "Join cluster..."
+
+ local erlang_node_name=${ERLANG_NODE%@*}
+ local erlang_cluster_node="${erlang_node_name}@${cluster_node}"
+
+ response=$(${EJABBERDCTL} ping ${erlang_cluster_node})
+ while [ "$response" != "pong" ]; do
+ echo "Waiting for ${erlang_cluster_node}..."
+ sleep 2
+ response=$(${EJABBERDCTL} ping ${erlang_cluster_node})
+ done
+
+ echo "Join cluster at ${erlang_cluster_node}... "
+ NO_WARNINGS=true ${EJABBERDCTL} join_cluster $erlang_cluster_node
+
+ if [ $? -eq 0 ]; then
+ touch ${CLUSTER_NODE_FILE}
+ else
+ echo "cloud not join cluster"
+ exit 1
+ fi
+}
diff --git a/docker/scripts/lib/config.sh b/docker/scripts/lib/config.sh
new file mode 100644
index 000000000..6b9cbbb12
--- /dev/null
+++ b/docker/scripts/lib/config.sh
@@ -0,0 +1 @@
+# Overridable file
diff --git a/docker/scripts/lib/functions.sh b/docker/scripts/lib/functions.sh
new file mode 100644
index 000000000..6b9cbbb12
--- /dev/null
+++ b/docker/scripts/lib/functions.sh
@@ -0,0 +1 @@
+# Overridable file