-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
70 lines (59 loc) · 1.73 KB
/
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
#!/bin/bash
set -e
terminate_processes() {
echo "Stoping postgres..."
gosu postgres /opt/pgpro/1c-16/bin/pg_ctl -D "$PGDATA" stop
pgagent_pid=$(ps -eo pid,cmd | grep 'pgagent' | grep -v grep | awk '{print $1}')
if [ -n "$pgagent_pid" ]; then
echo "Stopping pgagent $pgagent_pid ..."
kill -SIGTERM "$pgagent_pid"
wait "$pgagent_pid"
echo "pgagent stopped."
else
echo "There is no pgagent PID"
fi
echo "Processes stopped."
exit 0
}
trap 'terminate_processes' SIGTERM SIGINT
initialize_database() {
if [ -s "$PGDATA/PG_VERSION" ]; then
return
fi
chown -R postgres:postgres "$PGDATA"
if [ -n "$PG_PASSWORD" ]; then
gosu postgres sh -c 'echo "$PG_PASSWORD" > /tmp/password_file'
gosu postgres ./initdb --pwfile=/tmp/password_file
else
gosu postgres ./initdb
fi
echo "synchronous_commit = off" >> "$PGDATA/postgresql.conf"
echo "unix_socket_directories = '/tmp,$PGSOCKET'" >> "$PGDATA/postgresql.conf"
echo "listen_addresses = '*'" >> "$PGDATA/postgresql.conf"
echo "host all all 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf"
cat /pgdefault.conf >> /var/lib/1c/pgdata/postgresql.conf
rm /pgdefault.conf
}
initialize_socket() {
if [ -d "$PGSOCKET" ]; then
chown postgres $PGSOCKET
return
fi
mkdir -p $PGSOCKET
chown postgres $PGSOCKET
}
start_processes() {
echo "Staring pgagent..."
gosu postgres pgagent -f host=$PGSOCKET dbname=postgres &
pgagent_pid=$!
echo "Starting postgres..."
gosu postgres ./postgres &
postgres_pid=$!
wait "$postgres_pid"
}
if [ "$1" = './postgres' ]; then
initialize_database
initialize_socket
start_processes
fi
exec "$@"