Skip to content

Commit 925b253

Browse files
Fix init script multiple time run (#47)
Signed-off-by: souravbiswassanto <[email protected]>
1 parent c981ad5 commit 925b253

File tree

18 files changed

+246
-215
lines changed

18 files changed

+246
-215
lines changed

role_scripts/10/primary/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -e
1818

1919
echo "Running as Primary"
20-
20+
BOOTSTRAP="false"
2121
# set password ENV
2222
export PGPASSWORD=${POSTGRES_PASSWORD:-postgres}
2323

@@ -29,7 +29,8 @@ if [ ! -e "$PGDATA/PG_VERSION" ]; then
2929
rm -rf "$PGDATA"/*
3030
chmod 0700 "$PGDATA"
3131
/scripts/initdb.sh
32+
BOOTSTRAP="true"
3233

3334
fi
34-
/run_scripts/role/start.sh
35+
/run_scripts/role/start.sh $BOOTSTRAP
3536
exec postgres

role_scripts/10/primary/start.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
16+
BOOTSTRAP=${1}
1717
# setup postgresql.conf
1818
touch /tmp/postgresql.conf
1919
echo "wal_level = replica" >>/tmp/postgresql.conf
@@ -83,27 +83,29 @@ echo
8383
psql+=(--username "$POSTGRES_USER" --dbname "$POSTGRES_DB")
8484
echo
8585

86-
# initialize database
87-
for f in "$INITDB"/*; do
88-
case "$f" in
89-
*.sh)
90-
echo "$0: running $f"
91-
. "$f"
92-
;;
93-
*.sql)
94-
echo "$0: running $f"
95-
"${psql[@]}" -f "$f"
96-
echo
97-
;;
98-
*.sql.gz)
99-
echo "$0: running $f"
100-
gunzip -c "$f" | "${psql[@]}"
101-
echo
102-
;;
103-
*) echo "$0: ignoring $f" ;;
104-
esac
105-
echo
106-
done
86+
if [[ "$BOOTSTRAP" == "true" ]];then
87+
# initialize database
88+
for f in "$INITDB"/*; do
89+
case "$f" in
90+
*.sh)
91+
echo "$0: running $f"
92+
. "$f"
93+
;;
94+
*.sql)
95+
echo "$0: running $f"
96+
"${psql[@]}" -f "$f"
97+
echo
98+
;;
99+
*.sql.gz)
100+
echo "$0: running $f"
101+
gunzip -c "$f" | "${psql[@]}"
102+
echo
103+
;;
104+
*) echo "$0: ignoring $f" ;;
105+
esac
106+
echo
107+
done
108+
fi
107109

108110
# stop server
109111
pg_ctl -D "$PGDATA" -m fast -w stop

role_scripts/11/primary/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -e
1818

1919
echo "Running as Primary"
20-
20+
BOOTSTRAP="false"
2121
# set password ENV
2222
export PGPASSWORD=${POSTGRES_PASSWORD:-postgres}
2323

@@ -29,7 +29,8 @@ if [ ! -e "$PGDATA/PG_VERSION" ]; then
2929
rm -rf "$PGDATA"/*
3030
chmod 0700 "$PGDATA"
3131
/scripts/initdb.sh
32+
BOOTSTRAP="true"
3233

3334
fi
34-
/run_scripts/role/start.sh
35+
/run_scripts/role/start.sh $BOOTSTRAP
3536
exec postgres

role_scripts/11/primary/start.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
16+
BOOTSTRAP=${1}
1717
# setup postgresql.conf
1818
touch /tmp/postgresql.conf
1919
echo "wal_level = replica" >>/tmp/postgresql.conf
@@ -92,27 +92,29 @@ echo
9292
psql+=(--username "$POSTGRES_USER" --dbname "$POSTGRES_DB")
9393
echo
9494

95-
# initialize database
96-
for f in "$INITDB"/*; do
97-
case "$f" in
98-
*.sh)
99-
echo "$0: running $f"
100-
. "$f"
101-
;;
102-
*.sql)
103-
echo "$0: running $f"
104-
"${psql[@]}" -f "$f"
105-
echo
106-
;;
107-
*.sql.gz)
108-
echo "$0: running $f"
109-
gunzip -c "$f" | "${psql[@]}"
110-
echo
111-
;;
112-
*) echo "$0: ignoring $f" ;;
113-
esac
114-
echo
115-
done
95+
if [[ "$BOOTSTRAP" == "true" ]];then
96+
# initialize database
97+
for f in "$INITDB"/*; do
98+
case "$f" in
99+
*.sh)
100+
echo "$0: running $f"
101+
. "$f"
102+
;;
103+
*.sql)
104+
echo "$0: running $f"
105+
"${psql[@]}" -f "$f"
106+
echo
107+
;;
108+
*.sql.gz)
109+
echo "$0: running $f"
110+
gunzip -c "$f" | "${psql[@]}"
111+
echo
112+
;;
113+
*) echo "$0: ignoring $f" ;;
114+
esac
115+
echo
116+
done
117+
fi
116118

117119
# stop server
118120
pg_ctl -D "$PGDATA" -m fast -w stop

role_scripts/12/primary/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -e
1818

1919
echo "Running as Primary"
20-
20+
BOOTSTRAP="false"
2121
# set password ENV
2222
export PGPASSWORD=${POSTGRES_PASSWORD:-postgres}
2323

@@ -29,7 +29,8 @@ if [ ! -e "$PGDATA/PG_VERSION" ]; then
2929
rm -rf "$PGDATA"/*
3030
chmod 0700 "$PGDATA"
3131
/scripts/initdb.sh
32+
BOOTSTRAP="true"
3233

3334
fi
34-
/run_scripts/role/start.sh
35+
/run_scripts/role/start.sh $BOOTSTRAP
3536
exec postgres

role_scripts/12/primary/start.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
16+
BOOTSTRAP=${1}
1717
# setup postgresql.conf
1818
touch /tmp/postgresql.conf
1919
echo "wal_level = replica" >>/tmp/postgresql.conf
@@ -108,27 +108,29 @@ echo
108108
psql+=(--username "$POSTGRES_USER" --dbname "$POSTGRES_DB")
109109
echo
110110

111-
# initialize database
112-
for f in "$INITDB"/*; do
113-
case "$f" in
114-
*.sh)
115-
echo "$0: running $f"
116-
. "$f"
117-
;;
118-
*.sql)
119-
echo "$0: running $f"
120-
"${psql[@]}" -f "$f"
121-
echo
122-
;;
123-
*.sql.gz)
124-
echo "$0: running $f"
125-
gunzip -c "$f" | "${psql[@]}"
126-
echo
127-
;;
128-
*) echo "$0: ignoring $f" ;;
129-
esac
130-
echo
131-
done
111+
if [[ "$BOOTSTRAP" == "true" ]];then
112+
# initialize database
113+
for f in "$INITDB"/*; do
114+
case "$f" in
115+
*.sh)
116+
echo "$0: running $f"
117+
. "$f"
118+
;;
119+
*.sql)
120+
echo "$0: running $f"
121+
"${psql[@]}" -f "$f"
122+
echo
123+
;;
124+
*.sql.gz)
125+
echo "$0: running $f"
126+
gunzip -c "$f" | "${psql[@]}"
127+
echo
128+
;;
129+
*) echo "$0: ignoring $f" ;;
130+
esac
131+
echo
132+
done
133+
fi
132134

133135
# stop server
134136
pg_ctl -D "$PGDATA" -m fast -w stop

role_scripts/13/primary/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -e
1818

1919
echo "Running as Primary"
20-
20+
BOOTSTRAP="false"
2121
# set password ENV
2222
export PGPASSWORD=${POSTGRES_PASSWORD:-postgres}
2323

@@ -29,7 +29,8 @@ if [ ! -e "$PGDATA/PG_VERSION" ]; then
2929
rm -rf "$PGDATA"/*
3030
chmod 0700 "$PGDATA"
3131
/scripts/initdb.sh
32+
BOOTSTRAP="true"
3233

3334
fi
34-
/run_scripts/role/start.sh
35+
/run_scripts/role/start.sh $BOOTSTRAP
3536
exec postgres

role_scripts/13/primary/start.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
16+
BOOTSTRAP=${1}
1717
# setup postgresql.conf
1818
touch /tmp/postgresql.conf
1919
echo "wal_level = replica" >>/tmp/postgresql.conf
@@ -109,27 +109,29 @@ echo
109109
psql+=(--username "$POSTGRES_USER" --dbname "$POSTGRES_DB")
110110
echo
111111

112-
# initialize database
113-
for f in "$INITDB"/*; do
114-
case "$f" in
115-
*.sh)
116-
echo "$0: running $f"
117-
. "$f"
118-
;;
119-
*.sql)
120-
echo "$0: running $f"
121-
"${psql[@]}" -f "$f"
122-
echo
123-
;;
124-
*.sql.gz)
125-
echo "$0: running $f"
126-
gunzip -c "$f" | "${psql[@]}"
127-
echo
128-
;;
129-
*) echo "$0: ignoring $f" ;;
130-
esac
131-
echo
132-
done
112+
if [[ "$BOOTSTRAP" == "true" ]];then
113+
# initialize database
114+
for f in "$INITDB"/*; do
115+
case "$f" in
116+
*.sh)
117+
echo "$0: running $f"
118+
. "$f"
119+
;;
120+
*.sql)
121+
echo "$0: running $f"
122+
"${psql[@]}" -f "$f"
123+
echo
124+
;;
125+
*.sql.gz)
126+
echo "$0: running $f"
127+
gunzip -c "$f" | "${psql[@]}"
128+
echo
129+
;;
130+
*) echo "$0: ignoring $f" ;;
131+
esac
132+
echo
133+
done
134+
fi
133135

134136
# stop server
135137
pg_ctl -D "$PGDATA" -m fast -w stop

role_scripts/14/primary/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -e
1818

1919
echo "Running as Primary"
20-
20+
BOOTSTRAP="false"
2121
# set password ENV
2222
export PGPASSWORD=${POSTGRES_PASSWORD:-postgres}
2323

@@ -29,7 +29,8 @@ if [ ! -e "$PGDATA/PG_VERSION" ]; then
2929
rm -rf "$PGDATA"/*
3030
chmod 0700 "$PGDATA"
3131
/scripts/initdb.sh
32+
BOOTSTRAP="true"
3233

3334
fi
34-
/run_scripts/role/start.sh
35+
/run_scripts/role/start.sh $BOOTSTRAP
3536
exec postgres

role_scripts/14/primary/start.sh

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
16+
BOOTSTRAP=${1}
1717
# setup postgresql.conf
1818
touch /tmp/postgresql.conf
1919
echo "wal_level = replica" >>/tmp/postgresql.conf
@@ -115,27 +115,29 @@ echo
115115
psql+=(--username "$POSTGRES_USER" --dbname "$POSTGRES_DB")
116116
echo
117117

118-
# initialize database
119-
for f in "$INITDB"/*; do
120-
case "$f" in
121-
*.sh)
122-
echo "$0: running $f"
123-
. "$f"
124-
;;
125-
*.sql)
126-
echo "$0: running $f"
127-
"${psql[@]}" -f "$f"
128-
echo
129-
;;
130-
*.sql.gz)
131-
echo "$0: running $f"
132-
gunzip -c "$f" | "${psql[@]}"
133-
echo
134-
;;
135-
*) echo "$0: ignoring $f" ;;
136-
esac
137-
echo
138-
done
118+
if [[ "$BOOTSTRAP" == "true" ]];then
119+
# initialize database
120+
for f in "$INITDB"/*; do
121+
case "$f" in
122+
*.sh)
123+
echo "$0: running $f"
124+
. "$f"
125+
;;
126+
*.sql)
127+
echo "$0: running $f"
128+
"${psql[@]}" -f "$f"
129+
echo
130+
;;
131+
*.sql.gz)
132+
echo "$0: running $f"
133+
gunzip -c "$f" | "${psql[@]}"
134+
echo
135+
;;
136+
*) echo "$0: ignoring $f" ;;
137+
esac
138+
echo
139+
done
140+
fi
139141

140142
# stop server
141143
pg_ctl -D "$PGDATA" -m fast -w stop

0 commit comments

Comments
 (0)