forked from telephoneorg/docker-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint
executable file
·108 lines (83 loc) · 2.31 KB
/
entrypoint
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
#!/bin/bash -l
set -e
APP=couchdb
USER=$APP
if [ -f /etc/default/$APP ]; then
. /etc/default/$APP
fi
: declare -ir ${ERLANG_THREADS:=25}
# options: debug info warning error none
: readonly ${COUCHDB_LOG_LEVEL:=info}
: readonly ${COUCHDB_DATA_PATH:=/data/$APP}
: readonly ${COUCHDB_BIND_ADDR:=0.0.0.0}
: readonly ${COUCHDB_REQUIRE_VALID_USER:=false}
: declare -ir ${COUCHDB_SHARDS:=4}
: declare -ir ${COUCHDB_READ_QUORUM:=1}
: declare -ir ${COUCHDB_WRITE_QUORUM:=1}
: declare -ir ${COUCHDB_REPLICAS:=3}
function log() {
local msg=$1
local date=$(date "+%Y-%m-%d %H:%M:%S")
echo -e "\E[36m[*]\E[0m [$date]: $msg"
}
function errlog() {
local msg=$1
local date=$(date "+%Y-%m-%d %H:%M:%S")
echo -e "\E[31m[x]\E[0m [$date]: $msg" >&2
}
log "Writing vm.args file ..."
tee ~/etc/vm.args <<EOF
# Turn off the sasl error logger
-sasl sasl_error_logger false
# Use the following erlang long hostname
-name couchdb
# Use kernel poll functionality if supported by emulator
+K true
# Start a pool of asynchronous IO threads
+A $ERLANG_THREADS
# Turn off the kernel error_logger
-kernel error_logger silent
# Set erlang distribution to use 11500-11999 ports instead of random
# predictibility has value here
-kernel inet_dist_listen_min 11500 inet_dist_listen_max 11999
# Comment this line out if you want the Erlang shell
+Bd -noinput
EOF
log "Rewriting local.ini file ..."
tee ~/etc/local.ini <<EOF
[couchdb]
database_dir = $COUCHDB_DATA_PATH
view_index_dir = $COUCHDB_DATA_PATH
[chttpd]
require_valid_user = $COUCHDB_REQUIRE_VALID_USER
port = 5984
bind_address = $COUCHDB_BIND_ADDR
[httpd]
require_valid_user = $COUCHDB_REQUIRE_VALID_USER
port = 5986
bind_address = $COUCHDB_BIND_ADDR
[cluster]
q=$COUCHDB_SHARDS
n=$COUCHDB_REPLICAS
r=$COUCHDB_READ_QUORUM
w=$COUCHDB_WRITE_QUORUM
[log]
level = ${COUCHDB_LOG_LEVEL,,}
EOF
rm -rf ~/.erlang.cookie
echo "Cookie is: ${ERLANG_COOKIE:-insecure-cookie}"
echo "${ERLANG_COOKIE:-insecure-cookie}" > ~/.erlang.cookie
chown $USER:$USER ~/.erlang.cookie
chmod 600 $_
cat $_
log "Ensuring correct permissions ..."
chown -R $USER:$USER \
~ \
/{volumes,data}/$APP \
/volumes/$APP/{data,dumps,templates,config}
cd ~
log "Starting $APP ..."
# for interpreting crash dumps see:
# http://erlang.org/doc/apps/erts/crash_dump.html
export ERL_CRASH_DUMP=/dev/termination-log
exec gosu $USER couchdb 2>&1