-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path_functions_cmis.sh
141 lines (120 loc) · 4.75 KB
/
_functions_cmis.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
#!/bin/bash -eu
# Don't load it several times
set +u
${_FUNCTIONS_CMIS_LOADED:-false} && return
set -u
# if the script was started from the base directory, then the
# expansion returns a period
if test "${SCRIPT_DIR}" == "."; then
SCRIPT_DIR="$PWD"
# if the script was not called with an absolute path, then we need to add the
# current working directory to the relative path of the script
elif test "${SCRIPT_DIR:0:1}" != "/"; then
SCRIPT_DIR="$PWD/${SCRIPT_DIR}"
fi
do_get_cmis_settings() {
if ! ${DEPLOYMENT_CMISSERVER_ENABLED}; then
return;
fi
env_var DEPLOYMENT_CMIS_CONTAINER_NAME "${INSTANCE_KEY}_cmis"
}
#
# Drops all CMIS Server datas used by the instance.
#
do_drop_cmis_data() {
echo_info "Dropping CMIS Server data ..."
if ${DEPLOYMENT_CMISSERVER_ENABLED}; then
echo_info "Drops CMIS Server container ${DEPLOYMENT_CMIS_CONTAINER_NAME} ..."
delete_docker_container ${DEPLOYMENT_CMIS_CONTAINER_NAME}
echo_info "Drops CMIS Server docker volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_logs ..."
delete_docker_volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_logs
echo_info "Drops CMIS Server docker volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_data ..."
delete_docker_volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_data
echo_info "Done."
echo_info "CMIS Server data dropped"
else
echo_info "Skip Drops CMIS Server container ..."
fi
}
do_create_cmis() {
if ${DEPLOYMENT_CMISSERVER_ENABLED}; then
echo_info "Creation of the CMIS Server Docker volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_logs ..."
create_docker_volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_logs
echo_info "Creation of the CMIS Server Docker volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_data ..."
create_docker_volume ${DEPLOYMENT_CMIS_CONTAINER_NAME}_data
fi
}
do_stop_cmis() {
echo_info "Stopping CMIS Server ..."
if ! ${DEPLOYMENT_CMISSERVER_ENABLED}; then
echo_info "CMIS Server wasn't started, skiping its server container shutdown"
return
fi
ensure_docker_container_stopped ${DEPLOYMENT_CMIS_CONTAINER_NAME}
echo_info "CMIS Server container ${DEPLOYMENT_CMIS_CONTAINER_NAME} stopped."
}
do_start_cmis() {
echo_info "Starting CMIS Server..."
if ! ${DEPLOYMENT_CMISSERVER_ENABLED}; then
echo_info "CMIS Server wasn't specified, skiping its server container startup"
return
fi
echo_info "Starting CMIS Server container ${DEPLOYMENT_CMIS_CONTAINER_NAME} based on image ${DEPLOYMENT_CMIS_IMAGE}:${DEPLOYMENT_CMIS_IMAGE_VERSION}"
local DOCKER_ENV=""
DOCKER_ENV="${DOCKER_ENV} -e PROXY_VHOST=${DEPLOYMENT_CMIS_HOST}"
if ${DEPLOYMENT_APACHE_HTTPS_ENABLED}; then
DOCKER_ENV="${DOCKER_ENV} -e PROXY_SSL=true -e PROXY_PORT=443"
else
DOCKER_ENV="${DOCKER_ENV} -e PROXY_SSL=false -e PROXY_PORT=80"
fi
if [ -n "${DEPLOYMENT_CMIS_USERS_PASSWORD}" ]; then
DOCKER_ENV="${DOCKER_ENV} -e CMIS_USERS_PASSWORD='${DEPLOYMENT_CMIS_USERS_PASSWORD}'"
fi
# Ensure there is no container with the same name
delete_docker_container ${DEPLOYMENT_CMIS_CONTAINER_NAME}
${DOCKER_CMD} run \
-d ${DOCKER_ENV} \
-p "127.0.0.1:${DEPLOYMENT_CMIS_HTTP_PORT}:8080" \
-v ${DEPLOYMENT_CMIS_CONTAINER_NAME}_logs:/opt/cmis-server/logs \
-v ${DEPLOYMENT_CMIS_CONTAINER_NAME}_data:/data \
--name ${DEPLOYMENT_CMIS_CONTAINER_NAME} ${DEPLOYMENT_CMIS_IMAGE}:${DEPLOYMENT_CMIS_IMAGE_VERSION}
echo_info "${DEPLOYMENT_CMIS_CONTAINER_NAME} container started"
check_cmis_availability
}
check_cmis_availability() {
echo_info "Waiting for CMIS Server availability on port ${DEPLOYMENT_CMIS_HTTP_PORT}"
local count=0
local try=600
local wait_time=1
local RET=-1
local temp_file="/tmp/${DEPLOYMENT_CMIS_CONTAINER_NAME}_${DEPLOYMENT_CMIS_HTTP_PORT}.txt"
while [ $count -lt $try -a $RET -ne 0 ]; do
count=$(( $count + 1 ))
set +e
curl -s -q --max-time ${wait_time} http://localhost:${DEPLOYMENT_CMIS_HTTP_PORT} > temp_file
RET=$?
if [ $RET -ne 0 ]; then
[ $(( ${count} % 10 )) -eq 0 ] && echo_info "CMIS server not yet available (${count} / ${try})..."
else
curl -f -s --max-time ${wait_time} http://localhost:${DEPLOYMENT_CMIS_HTTP_PORT}/cmis/ > ${temp_file}
local status=$(grep "[Y]our server is up and running." ${temp_file}| wc -l)
if [ "${status}" == "1" ]; then
RET=0
fi
fi
if [ $RET -ne 0 ]; then
echo -n "."
sleep $wait_time
fi
set -e
done
if [ $count -eq $try ]; then
echo_error "CMIS Server ${DEPLOYMENT_CMIS_CONTAINER_NAME} not available after $(( ${count} * ${wait_time}))s"
exit 1
fi
echo_info "CMIS Server ${DEPLOYMENT_CMIS_CONTAINER_NAME} up and available"
}
# #############################################################################
# Env var to not load it several times
_FUNCTIONS_CMIS_LOADED=true
echo_debug "_functions_cmis.sh Loaded"