-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
72 lines (55 loc) · 2.07 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
#!/bin/bash
# @author Michael Wiesendanger <michael.wiesendanger@gmail.com>
# @description launch script for jira
set -euo pipefail
postgresql_app_user="/run/secrets/com.ragedunicorn.postgresql.app_user"
postgresql_app_password="/run/secrets/com.ragedunicorn.postgresql.app_user_password"
function connection_check {
loop_limit=13
i=1
while true
do
if [ ${i} -eq ${loop_limit} ]; then
echo "$(date) [ERROR]: Timeout error, failed to connect to PostgreSQL server"
exit 1
fi
echo "$(date) [INFO]: Waiting for connection to PostgreSQL, trying ${i}/${loop_limit}..."
if pg_isready -h "${POSTGRESQL_DATABASE_HOSTNAME}" -U "${postgresql_app_user}"; then
break
fi
sleep 5
i=$((i + 1))
done
}
function database_check {
if psql -h "${POSTGRESQL_DATABASE_HOSTNAME}" -U "${postgresql_app_user}" -w -lqt | cut -d \| -f 1 | grep -qw "${JIRA_DATABASE_NAME}"; then
echo "$(date) [INFO]: Jira database already exists"
else
echo "$(date) [INFO]: Creating Jira database"
createdb -h "${POSTGRESQL_DATABASE_HOSTNAME}" -U "${postgresql_app_user}" -w "${JIRA_DATABASE_NAME}"
fi
}
function setup_credentials {
if [ -f "${postgresql_app_user}" ] && [ -f "${postgresql_app_password}" ]; then
echo "$(date) [INFO]: Found docker secrets - using secrets"
postgresql_app_user="$(cat ${postgresql_app_user})"
postgresql_app_password="$(cat ${postgresql_app_password})"
else
echo "$(date) [INFO]: No docker secrets found - using environment variables"
postgresql_app_user="${POSTGRESQL_APP_USER:?Missing environment variable POSTGRESQL_APP_USER}"
postgresql_app_password="${POSTGRESQL_APP_PASSWORD:?Missing environment variable POSTGRESQL_APP_PASSWORD}"
fi
# used by is_pgready/createdb
export PGPASSWORD="${postgresql_app_password}"
unset "${POSTGRESQL_APP_USER}"
unset "${POSTGRESQL_APP_PASSWORD}"
}
function init {
setup_credentials
connection_check
database_check
unset "${PGPASSWORD}"
echo "$(date) [INFO]: Starting Jira..."
exec su-exec "${JIRA_USER}" /opt/atlassian/jira/bin/start-jira.sh -fg run
}
init