directory;
mkdir -p /var/run/mogdb || :
chmod 775 /var/run/mogdb || :
# Create the transaction log directory before initdb is run so the directory
is owned by
the correct user
if [ -n "$POSTGRES_INITDB_XLOGDIR" ]; then
mkdir -p "$POSTGRES_INITDB_XLOGDIR"
if [ "$user" = '0' ]; then
find "$POSTGRES_INITDB_XLOGDIR" \! -user postgres -exec chown
postgres '{
}' +
fi
chmod 700 "$POSTGRES_INITDB_XLOGDIR"
fi
# allow the container to be started with `--user`
if [ "$user" = '0' ]; then
find "$PGDATA" \! -user omm -exec chown omm '{}' +
find /var/run/mogdb \! -user omm -exec chown omm '{}' +
fi
}
# initialize empty PGDATA directory with new database via 'initdb'
# arguments to `initdb` can be passed via POSTGRES_INITDB_ARGS or as arguments
to this function
# `initdb` automatically creates the "postgres", "template0", and "template1"
dbnames
# this is also where the database user is created, specified by `GS_USER` env
# 自定义变量,逻辑为若有传入则使用,没有则使用默认,其中包括
GS_NODENAME、ENCODING、LOCALE、DBCOMPATIBILITY
docker_init_database_dir() {
# "initdb" is particular about the current user existing in "/etc/passwd",
so we use "nss
_wrapper" to fake that if necessary
if ! getent passwd "$(id -u)" &> /dev/null && [ -e
/usr/lib/libnss_wrapper.so ]; then
export LD_PRELOAD='/usr/lib/libnss_wrapper.so'
export NSS_WRAPPER_PASSWD="$(mktemp)"
export NSS_WRAPPER_GROUP="$(mktemp)"
echo "postgres:x:$(id -u):$(id -g):PostgreSQL:$PGDATA:/bin/false" >
"$NSS_WRAPPER
_PASSWD"
echo "postgres:x:$(id -g):" > "$NSS_WRAPPER_GROUP"
fi
if [ -n "$POSTGRES_INITDB_XLOGDIR" ]; then
set -- --xlogdir "$POSTGRES_INITDB_XLOGDIR" "$@"
fi
cmdbase="gs_initdb --pwfile=<(echo "$GS_PASSWORD")"
if [ -n "$GS_NODENAME" ]; then
cmdbase="$cmdbase --nodename=$GS_NODENAME"
评论