-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint-common.sh
More file actions
executable file
·77 lines (64 loc) · 1.91 KB
/
docker-entrypoint-common.sh
File metadata and controls
executable file
·77 lines (64 loc) · 1.91 KB
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
#!/usr/bin/env bash
if [ -z "${UNIT_ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&2
else
exec 3>/dev/null
fi
ngx_log() {
local type="$1"
shift
printf '%s [%s] %s#%s [entrypoint] #0: %s\n' "$(date +'%Y/%m/%d %H:%M:%S')" "$type" "$$" "$$" "$*" >&3
}
ngx_err() {
ngx_log err "$@"
exit 1
}
ngx_error() {
ngx_err "$@"
}
ngx_warn() {
ngx_log warning "$@"
}
ngx_warning() {
ngx_warn "$@"
}
ngx_notice() {
ngx_log notice "$@"
}
ngx_info() {
ngx_log info "$@"
}
curl_put() {
RET=$(curl -s -w '%{http_code}' -X PUT --data-binary "@$1" --unix-socket /var/run/control.unit.sock "http://localhost/$2")
RET_BODY=${RET::-3}
RET_STATUS=$(echo "$RET" | tail -c 4)
if [ "$RET_STATUS" -ne "200" ]; then
ngx_err "HTTP response status code is '$RET_STATUS'. Body: $RET_BODY"
else
ngx_info "HTTP response status code is '$RET_STATUS'. Body: $RET_BODY"
fi
return 0
}
APPLICATION_USER=${APPLICATION_USER:="unit"}
APPLICATION_UID=${APPLICATION_UID:="1000"}
APPLICATION_GROUP=${APPLICATION_GROUP:="unit"}
APPLICATION_GID=${APPLICATION_GID:="1000"}
APPLICATION_CHOWN=${APPLICATION_CHOWN:="yes"}
if [ -z $(getent group "$APPLICATION_GROUP") ]; then
ngx_info "create app group: '$APPLICATION_GROUP'"
groupadd "$APPLICATION_GROUP" -g "$APPLICATION_GID"
fi
if [ -z $(getent passwd "$APPLICATION_USER") ]; then
ngx_info "create app user: '$APPLICATION_USER'"
useradd -M -s /bin/bash -g "$APPLICATION_GROUP" -u "$APPLICATION_UID" "$APPLICATION_USER"
fi
if [ -n "$APPLICATION_DIR" ]; then
if [ ! -d "$APPLICATION_DIR" ]; then
ngx_info "create app dir: '$APPLICATION_DIR'"
mkdir -p "$APPLICATION_DIR"
fi
usermod --home "$APPLICATION_DIR" "$APPLICATION_USER" &>/dev/null
if [ "x$APPLICATION_CHOWN" = "xyes" ]; then
find "$APPLICATION_DIR" \! -user "$APPLICATION_USER" -exec chown "$APPLICATION_USER":"$APPLICATION_GROUP" '{}' +
fi
fi