-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindme.txt
More file actions
199 lines (186 loc) · 7.54 KB
/
findme.txt
File metadata and controls
199 lines (186 loc) · 7.54 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
diff --git a/files/_debug b/files/_debug
index f531182..6607f20 100644
--- a/files/_debug
+++ b/files/_debug
@@ -1,3 +1,5 @@
docker run -i -t
+ -e 'PGUSER=$POSTGRES_ADMIN_USERNAME'
+ -e 'DAEMON=true'
-v $POSTGRES_LOG_DIR:/log
-v $POSTGRES_DATA_DIR:/var/lib/postgresql/data
diff --git a/files/bin/gosu b/files/bin/gosu
old mode 100644
new mode 100755
diff --git a/files/bin/gosu.asc b/files/bin/gosu.asc
old mode 100644
new mode 100755
diff --git a/files/postgres.dockerfile b/files/postgres.dockerfile
index 87d058a..e212cda 100644
--- a/files/postgres.dockerfile
+++ b/files/postgres.dockerfile
@@ -3,17 +3,6 @@ FROM phusion/baseimage:0.9.16
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r postgres && useradd -r -g postgres postgres
-ADD bin /usr/local/dockerbin
-ENV PATH /usr/local/dockerbin:$PATH
-
-# grab gosu for easy step-down from root
-RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
-RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
- && gpg --verify /usr/local/dockerbin/gosu.asc \
- && rm /usr/local/dockerbin/gosu.asc \
- && chmod +x /usr/local/dockerbin/gosu \
- && apt-get purge -y --auto-remove curl
-
# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
@@ -42,13 +31,21 @@ ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
ENV PGDATA /var/lib/postgresql/data
VOLUME /var/lib/postgresql/data
-ADD config/psqlentry /usr/local/bin/psqlentry
-RUN chmod +x /usr/local/bin/psqlentry
+ADD bin /usr/local/dockerbin
+ENV PATH /usr/local/dockerbin:$PATH
+
+# grab gosu for easy step-down from root
+RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
+RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
+ && gpg --verify /usr/local/dockerbin/gosu.asc \
+ && rm /usr/local/dockerbin/gosu.asc \
+ && chmod -R +x /usr/local/dockerbin/ \
+ && apt-get purge -y --auto-remove curl
RUN echo "psql -h \$PSQLDB_PORT_5432_TCP_ADDR -p \$PSQLDB_PORT_5432_TCP_PORT -U postgres \$@" > /usr/local/bin/psqldb && \
chmod 755 /usr/local/bin/psqldb
-ENTRYPOINT ["/usr/local/bin/psqlentry"]
+ENTRYPOINT ["/usr/local/dockerbin/psqlentry"]
EXPOSE 5432
CMD ["postgres"]
diff --git a/files/psqlentry b/files/psqlentry
deleted file mode 100644
index 5508cc4..0000000
--- a/files/psqlentry
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-set -e
-
-if [ "$1" = 'postgres' ]; then
- chown -R postgres "$PGDATA"
- chmod g+s /run/postgresql
- chown -R postgres:postgres /run/postgresql
- if [ -z "$(ls -A "$PGDATA")" ]; then
- gosu postgres initdb
- sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
- { echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
- fi
- exec gosu postgres "$@"
-elif [ "$1" = 'init' ]; then
- if [[ ! -e "$PGDATA"/PG_VERSION ]]; then
- chown -R postgres "$PGDATA"
- chmod g+s /run/postgresql
- chown -R postgres:postgres /run/postgresql
- gosu postgres initdb
- sed -ri "s/^#(listen_addresses\s*=\s*)\S+/\1'*'/" "$PGDATA"/postgresql.conf
- { echo; echo 'host all all 0.0.0.0/0 trust'; } >> "$PGDATA"/pg_hba.conf
- fi
-
- exit 1;
-fi
-
-exec "$@"
diff --git a/install b/install
old mode 100755
new mode 100644
index 26cb997..f8cccf6
--- a/install
+++ b/install
@@ -11,9 +11,11 @@ export POSTGRES_LAUNCHER_DIR=${POSTGRES_LAUNCHER_DIR-$LAUNCHER_DIR/postgres}
export DATA_DIR=${DATA_DIR-/var/local/data}
export LOG_DIR=${LOG_DIR-/var/log}
+export SENSITIVE_DIR=${SENSITIVE_DIR-/var/local/sensitive}
+
export POSTGRES_LOG_DIR=${POSTGRES_LOG_DIR-$LOG_DIR/postgres}
export POSTGRES_DATA_DIR=${POSTGRES_DATA_DIR-$DATA_DIR/postgres}
-export POSTGRES_SENSITIVE_DIR=${POSTGRES_SENSITIVE_DIR-/var/local/sensitive/postgres}
+export POSTGRES_SENSITIVE_DIR=${POSTGRES_SENSITIVE_DIR-$SENSITIVE_DIR/postgres}
export POSTGRES_PORT=${POSTGRES_PORT-5432}
export POSTGRES_HOST=${POSTGRES_HOST-"127.0.0.1:"}
POSTGRES_ADMIN_USERNAME=${POSTGRES_ADMIN_USERNAME-postgres}
@@ -71,11 +73,13 @@ OWNER=$LAUNCHER_OWNER ./bits/bootstrap/mkdir \
$POSTGRES_LAUNCHER_DIR/bin
cp ./bits/postgres/files/postgres.dockerfile ${POSTGRES_LAUNCHER_DIR}/Dockerfile
-TEMPLATE=./bits/postgres/files/psqlentry LOCATION=${POSTGRES_LAUNCHER_DIR}/config/psqlentry ./bits/docker/copyif
TEMPLATE=./bits/postgres/files/bin LOCATION=$POSTGRES_LAUNCHER_DIR/bin ./bits/docker/copyallif
-LAUNCHER_DIR=$POSTGRES_LAUNCHER_DIR NAME=postgres ./bits/docker/build
-NAME=postgres DIR=$POSTGRES_LAUNCHER_DIR BIT=postgres ./bits/docker/helpers
+debug " -- Making logger available on node"
+./bits/bootstrap/cp ./bits/bootstrap/logging $POSTGRES_LAUNCHER_DIR/bin/logging
+./bits/bootstrap/cp ./bits/bootstrap/failonerrors $POSTGRES_LAUNCHER_DIR/bin/failonerrors
+
+LAUNCHER_DIR=$POSTGRES_LAUNCHER_DIR NAME=postgres ./bits/docker/build
echo "#!/bin/bash
# Don't run under -i as this script is called remotely via capistrano
@@ -89,44 +93,6 @@ exit 0
" > ${POSTGRES_LAUNCHER_DIR}/init
printf "%b" "#!/bin/bash
-source logging
-CONTAINER_ID=\`${POSTGRES_LAUNCHER_DIR}/running\`
-if [[ \"\$CONTAINER_ID\" == \"\" ]]; then
- notify \"Starting POSTGRES ($POSTGRES_PORT, $POSTGRES_DATA_DIR)...\"
-
- debug \" -- Removing any stopped postgres containers\"
- docker rm postgres > /dev/null 2>&1
- debug \" -- Starting docker\"
- docker run -d -t \\
- -p ${POSTGRES_HOST}${POSTGRES_PORT}:5432 \\
- -v ${POSTGRES_LOG_DIR}:/log \\
- -v ${POSTGRES_DATA_DIR}:/var/lib/postgresql/data \\
- --name postgres \\
- postgres 2> /dev/null > ${POSTGRES_LAUNCHER_DIR}/container.pid
-
- IP=\$(${POSTGRES_LAUNCHER_DIR}/ip)
-
- if [[ \"\$IP\" == '' ]]; then
- debug ' -- No IP address assigned when starting POSTGRES, not sure what went wrong.'
- exit 1
- fi
-
- if [[ \"\`cat /etc/hosts | grep postgres.local\`\" == '' ]]; then
- debug \" -- Adding postgres.local (\$IP) to /etc/hosts\"
- echo \"\$IP postgres.local\" >> /etc/hosts
- else
- debug \" -- Updating postgres.local (\$IP) in /etc/hosts\"
- sed -i \"s|.*postgres.local|\$IP postgres.local|g\" /etc/hosts
- fi
-
- notify \"DONE, Starting POSTGRES \$IP\"
-else
- debug \"Container postgres already running, ${POSTGRES_LAUNCHER_DIR}/restart to restart it\"
-fi
-" > ${POSTGRES_LAUNCHER_DIR}/start
-
-
-printf "%b" "#!/bin/bash
USER=\${USER-$POSTGRES_ADMIN_USERNAME}
PASSWORD=\${PASSWORD-$POSTGRES_ADMIN_PASSWORD}
DATABASE=\${DATABASE}
@@ -195,7 +161,7 @@ echo \"PGHOST=postgres.local pg_restore --dbname=postgres --username=\$USER --ro
chmod 755 \$DBFILE \$DUMPFILE \$RESTOREFILE
" > ${POSTGRES_LAUNCHER_DIR}/accessdb
-NAME=postgres HOST=postgres.local DIR=$POSTGRES_LAUNCHER_DIR ./bits/docker/helpers
+NAME=postgres HOST=postgres.local DIR=$POSTGRES_LAUNCHER_DIR BIT=postgres ./bits/docker/helpers
chmod 755 $POSTGRES_LAUNCHER_DIR/init
chmod 755 $POSTGRES_LAUNCHER_DIR/start
@@ -208,6 +174,12 @@ SCRIPT_OUTPUT=$($POSTGRES_LAUNCHER_DIR/init > $PSQL_OUTPUT 2>&1)
ERROR="Unable to init postgres due to ..." ./bits/bootstrap/failonerrors $? $PSQL_OUTPUT
[ $? -ne 0 ] && exit 1
+if [[ "$OS" == "mac" ]]; then
+ debug " -- Permissions hack on $POSTGRES_DATA_DIR setting full access"
+ $SUDO chmod -R 700 $POSTGRES_DATA_DIR
+ $SUDO chown -R $LAUNCHER_OWNER $POSTGRES_DATA_DIR
+fi
+
if [[ -e ${POSTGRES_DATA_DIR}/PG_VERSION ]]; then
notify " -- Setting up postgres conf"
TEMPLATE=${POSTGRES_CONF} \