This repository has been archived by the owner on Apr 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdocker-entrypoint.sh
executable file
·143 lines (127 loc) · 4.35 KB
/
docker-entrypoint.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash -e
# =====================================================================
# Build script running OpenNMS in Docker environment
#
# Source: /~https://github.com/opennms-forge/docker-horizon-core-web
# Web: https://www.opennms.org
#
# =====================================================================
OPENNMS_HOME=/opt/opennms
OPENNMS_DATASOURCES_TPL=/root/opennms-datasources.xml.tpl
OPENNMS_DATASOURCES_CFG=${OPENNMS_HOME}/etc/opennms-datasources.xml
OPENNMS_OVERLAY_CFG=/opt/opennms-etc-overlay
OPENNMS_UPGRADE_GUARD=${OPENNMS_HOME}/etc/do-upgrade
OPENNMS_CONFIGURED_GUARD=${OPENNMS_HOME}/etc/configured
OPENNMS_KARAF_TPL=/root/org.apache.karaf.shell.cfg.tpl
OPENNMS_KARAF_CFG=${OPENNMS_HOME}/etc/org.apache.karaf.shell.cfg
# Error codes
E_ILLEGAL_ARGS=126
# Help function used in error messages and -h option
usage() {
echo ""
echo "Docker entry script for OpenNMS service container"
echo ""
echo "Overlay Config file:"
echo "If you want to overwrite the default configuration with your custom config, you can use an overlay config"
echo "folder in which needs to be mounted to ${OPENNMS_OVERLAY_CFG}."
echo "Every file in this folder is overwriting the default configuration file in ${OPENNMS_HOME}/etc."
echo ""
echo "-f: Start OpenNMS in foreground with an existing configuration."
echo "-h: Show this help."
echo "-i: Initialize Java environment, database and pristine OpenNMS configuration files and do *NOT* start OpenNMS."
echo " The database and config file initialization is skipped when a configured file exist."
echo "-s: Initialize environment like -i and start OpenNMS in foreground."
echo ""
}
doInitOrUpgrade() {
if [ -f ${OPENNMS_UPGRADE_GUARD} ]; then
echo "Enforce config and database update."
rm -rf ${OPENNMS_CONFIGURED_GUARD}
${OPENNMS_HOME}/bin/runjava -s
${OPENNMS_HOME}/bin/install -dis
rm -rf ${OPENNMS_UPGRADE_GUARD}
rm -rf ${OPENNMS_OVERLAY_CFG}/do-upgrade
fi
}
# Initialize database and configure Karaf
initConfig() {
if [ ! -d ${OPENNMS_HOME} ]; then
echo "OpenNMS home directory doesn't exist in ${OPENNMS_HOME}."
exit ${E_ILLEGAL_ARGS}
fi
if [ ! "$(ls --ignore .git --ignore .gitignore --ignore ${OPENNMS_DATASOURCES_CFG} --ignore ${OPENNMS_KARAF_CFG} -A ${OPENNMS_HOME}/etc)" ]; then
echo "No existing configuration in ${OPENNMS_HOME}/etc found. Initialize from etc-pristine."
cp -r ${OPENNMS_HOME}/share/etc-pristine/* ${OPENNMS_HOME}/etc/
fi
if [ ! -f ${OPENNMS_CONFIGURED_GUARD} ]; then
echo "Initialize database and Karaf configuration and do install or upgrade the database schema."
envsubst < ${OPENNMS_DATASOURCES_TPL} > ${OPENNMS_DATASOURCES_CFG}
envsubst < ${OPENNMS_KARAF_TPL} > ${OPENNMS_KARAF_CFG}
${OPENNMS_HOME}/bin/runjava -s
${OPENNMS_HOME}/bin/install -dis
fi
}
applyOverlayConfig() {
if [ "$(ls -A ${OPENNMS_OVERLAY_CFG})" ]; then
echo "Apply custom configuration from ${OPENNMS_OVERLAY_CFG}."
cp -r ${OPENNMS_OVERLAY_CFG}/* ${OPENNMS_HOME}/etc
else
echo "No custom config found in ${OPENNMS_OVERLAY_CFG}. Use default configuration."
fi
}
# Start opennms in foreground
start() {
local OPENNMS_JAVA_OPTS="-Djava.endorsed.dirs=/opt/opennms/lib/endorsed \
-Dopennms.home=/opt/opennms \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.login.config=opennms \
-Dcom.sun.management.jmxremote.access.file=/opt/opennms/etc/jmxremote.access \
-DisThreadContextMapInheritable=true \
-Dgroovy.use.classvalue=true \
-Djava.io.tmpdir=/opt/opennms/data/tmp"
exec java ${OPENNMS_JAVA_OPTS} ${JAVA_OPTS} -jar /opt/opennms/lib/opennms_bootstrap.jar start
}
# Evaluate arguments for build script.
if [[ "${#}" == 0 ]]; then
usage
exit ${E_ILLEGAL_ARGS}
fi
# Evaluate arguments for build script.
while getopts fhis flag; do
case ${flag} in
f)
applyOverlayConfig
start
exit
;;
h)
usage
exit
;;
i)
initConfig
applyOverlayConfig
doInitOrUpgrade
exit
;;
s)
initConfig
applyOverlayConfig
doInitOrUpgrade
start
exit
;;
*)
usage
exit ${E_ILLEGAL_ARGS}
;;
esac
done
# Strip of all remaining arguments
shift $((OPTIND - 1));
# Check if there are remaining arguments
if [[ "${#}" > 0 ]]; then
echo "Error: To many arguments: ${*}."
usage
exit ${E_ILLEGAL_ARGS}
fi