-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
120 lines (103 loc) · 5.37 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
#!/usr/bin/env bash
set -e
# print all comands to console if DEBUG is set
if [[ ! -z "${DEBUG}" ]]; then
set -x
fi
# set some helpful variables
export SERVICE_PROPERTY_FILE='etc/i5.las2peer.services.projectService.ProjectService.properties'
export WEB_CONNECTOR_PROPERTY_FILE='etc/i5.las2peer.connectors.webConnector.WebConnector.properties'
export SERVICE_VERSION=$(awk -F "=" '/service.version/ {print $2}' gradle.properties)
export SERVICE_NAME=$(awk -F "=" '/service.name/ {print $2}' gradle.properties)
export SERVICE_CLASS=$(awk -F "=" '/service.class/ {print $2}' gradle.properties)
export SERVICE=${SERVICE_NAME}.${SERVICE_CLASS}@${SERVICE_VERSION}
function set_in_service_config {
sed -i "s?${1}[[:blank:]]*=.*?${1}=${2}?g" ${SERVICE_PROPERTY_FILE}
}
# check mandatory variables
[[ -z "${SYSTEMS}" ]] && \
echo "Mandatory variable SYSTEMS is not set. Add -e SYSTEMS={...} to your arguments." && exit 1
set_in_service_config systems ${SYSTEMS}
# check if a new group agent should be generated for the service
if [[ -z "${NEW_GROUP_AGENT}" ]]; then
# NEW_GROUP_AGENT is undefined
# we want to add the service agent to an existing group
[[ -z "${OLD_SERVICE_AGENT_ID}" ]] && \
echo "Variable NEW_GROUP_AGENT is not set, but OLD_SERVICE_AGENT_ID is not set too. Cannot start service." && exit 1
[[ -z "${OLD_SERVICE_AGENT_PW}" ]] && \
echo "Variable NEW_GROUP_AGENT is not set, but OLD_SERVICE_AGENT_PW is not set too. Cannot start service." && exit 1
[[ -z "${SERVICE_GROUP_ID}" ]] && \
echo "Variable NEW_GROUP_AGENT is not set, but SERVICE_GROUP_ID is not set too. Cannot start service. Either set NEW_GROUP_AGENT or set SERVICE_GROUP_ID to the id of the previously used service group." && exit 1
set_in_service_config oldServiceAgentId ${OLD_SERVICE_AGENT_ID}
set_in_service_config oldServiceAgentPw ${OLD_SERVICE_AGENT_PW}
set_in_service_config serviceGroupId ${SERVICE_GROUP_ID}
else
# NEW_GROUP_AGENT is set
# Check if there does not exist a group agent yet
if [[ -f "etc/startup/group.xml" ]]; then
# group.xml exists
# do not do anything, we use the existing service and group agents
echo "There already exists a group.xml file. We use the existing service and group agent."
else
echo "Generating a new service agent..."
sh bin/start_ServiceAgentGenerator.sh ${SERVICE} ${SERVICE_PASSPHRASE} > "etc/startup/${SERVICE}.xml"
echo -e "\n${SERVICE}.xml;${SERVICE_PASSPHRASE}" >> "etc/startup/passphrases.txt"
echo "Generating a new group agent for the service..."
sh bin/start_GroupAgentGenerator.sh "etc/startup/${SERVICE}.xml" > "etc/startup/group.xml"
# extract id of group agent from group.xml file
groupId=`sed -n "s:.*<id>\(.*\)</id>.*:\1:p" "etc/startup/group.xml"`
echo "Group agent was generated. Group agent identifier is: $groupId"
echo "Using this group id as the service group id."
set_in_service_config serviceGroupId $groupId
fi
fi
# set defaults for optional web connector parameters
[[ -z "${START_HTTP}" ]] && export START_HTTP='TRUE'
[[ -z "${START_HTTPS}" ]] && export START_HTTPS='FALSE'
[[ -z "${SSL_KEYSTORE}" ]] && export SSL_KEYSTORE=''
[[ -z "${SSL_KEY_PASSWORD}" ]] && export SSL_KEY_PASSWORD=''
[[ -z "${CROSS_ORIGIN_RESOURCE_DOMAIN}" ]] && export CROSS_ORIGIN_RESOURCE_DOMAIN='*'
[[ -z "${CROSS_ORIGIN_RESOURCE_MAX_AGE}" ]] && export CROSS_ORIGIN_RESOURCE_MAX_AGE='60'
[[ -z "${ENABLE_CROSS_ORIGIN_RESOURCE_SHARING}" ]] && export ENABLE_CROSS_ORIGIN_RESOURCE_SHARING='TRUE'
[[ -z "${OIDC_PROVIDERS}" ]] && export OIDC_PROVIDERS='https://api.learning-layers.eu/o/oauth2,https://accounts.google.com'
# configure web connector properties
function set_in_web_config {
sed -i "s?${1}[[:blank:]]*=.*?${1}=${2}?g" ${WEB_CONNECTOR_PROPERTY_FILE}
}
set_in_web_config httpPort ${HTTP_PORT}
set_in_web_config httpsPort ${HTTPS_PORT}
set_in_web_config startHttp ${START_HTTP}
set_in_web_config startHttps ${START_HTTPS}
set_in_web_config sslKeystore ${SSL_KEYSTORE}
set_in_web_config sslKeyPassword ${SSL_KEY_PASSWORD}
set_in_web_config crossOriginResourceDomain "${CROSS_ORIGIN_RESOURCE_DOMAIN}"
set_in_web_config crossOriginResourceMaxAge ${CROSS_ORIGIN_RESOURCE_MAX_AGE}
set_in_web_config enableCrossOriginResourceSharing ${ENABLE_CROSS_ORIGIN_RESOURCE_SHARING}
set_in_web_config oidcProviders ${OIDC_PROVIDERS}
# wait for any bootstrap host to be available
if [[ ! -z "${BOOTSTRAP}" ]]; then
echo "Waiting for any bootstrap host to become available..."
for host_port in ${BOOTSTRAP//,/ }; do
arr_host_port=(${host_port//:/ })
host=${arr_host_port[0]}
port=${arr_host_port[1]}
if { </dev/tcp/${host}/${port}; } 2>/dev/null; then
echo "${host_port} is available. Continuing..."
break
fi
done
fi
echo external_address = $(curl -s https://ipinfo.io/ip):${LAS2PEER_PORT} >etc/pastry.properties
# prevent glob expansion in lib/*
set -f
LAUNCH_COMMAND='java -cp lib/* --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED i5.las2peer.tools.L2pNodeLauncher -s service -p '"${LAS2PEER_PORT} ${SERVICE_EXTRA_ARGS}"
if [[ ! -z "${BOOTSTRAP}" ]]; then
LAUNCH_COMMAND="${LAUNCH_COMMAND} -b ${BOOTSTRAP}"
fi
# start the service within a las2peer node
if [[ -z "${@}" ]]
then
exec ${LAUNCH_COMMAND} uploadStartupDirectory startService\("'""${SERVICE}""'", "'""${SERVICE_PASSPHRASE}""'"\) startWebConnector
else
exec ${LAUNCH_COMMAND} ${@}
fi