Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pre-exec startup scripts that execute whenever the container starts #267

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions 9.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ file_env() {
unset "$fileVar"
}

# Execute scripts from a given folder
# usage: exec_scripts FOLDER
exec_scripts() {
local execDir="$1"
local fileList=(${execDir}/*)
if [ ${#fileList[@]} -gt 0 ]; then
echo
for f in "${fileList[@]}"; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
fi
}

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
Expand All @@ -37,6 +56,7 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec_scripts "/docker-entrypoint-preexec.d"
exec gosu postgres "$BASH_SOURCE" "$@"
fi

Expand Down Expand Up @@ -110,15 +130,7 @@ if [ "$1" = 'postgres' ]; then
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
exec_scripts "/docker-entrypoint-initdb.d"

PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop
Expand All @@ -129,4 +141,5 @@ if [ "$1" = 'postgres' ]; then
fi
fi

exec_scripts "/docker-entrypoint-preexec.d"
exec "$@"
31 changes: 22 additions & 9 deletions 9.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ file_env() {
unset "$fileVar"
}

# Execute scripts from a given folder
# usage: exec_scripts FOLDER
exec_scripts() {
local execDir="$1"
local fileList=(${execDir}/*)
if [ ${#fileList[@]} -gt 0 ]; then
echo
for f in "${fileList[@]}"; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
fi
}

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
Expand All @@ -37,6 +56,7 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec_scripts "/docker-entrypoint-preexec.d"
exec gosu postgres "$BASH_SOURCE" "$@"
fi

Expand Down Expand Up @@ -110,15 +130,7 @@ if [ "$1" = 'postgres' ]; then
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
exec_scripts "/docker-entrypoint-initdb.d"

PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop
Expand All @@ -129,4 +141,5 @@ if [ "$1" = 'postgres' ]; then
fi
fi

exec_scripts "/docker-entrypoint-preexec.d"
exec "$@"
31 changes: 22 additions & 9 deletions 9.4/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ file_env() {
unset "$fileVar"
}

# Execute scripts from a given folder
# usage: exec_scripts FOLDER
exec_scripts() {
local execDir="$1"
local fileList=(${execDir}/*)
if [ ${#fileList[@]} -gt 0 ]; then
echo
for f in "${fileList[@]}"; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
fi
}

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
Expand All @@ -37,6 +56,7 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec_scripts "/docker-entrypoint-preexec.d"
exec gosu postgres "$BASH_SOURCE" "$@"
fi

Expand Down Expand Up @@ -110,15 +130,7 @@ if [ "$1" = 'postgres' ]; then
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
exec_scripts "/docker-entrypoint-initdb.d"

PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop
Expand All @@ -129,4 +141,5 @@ if [ "$1" = 'postgres' ]; then
fi
fi

exec_scripts "/docker-entrypoint-preexec.d"
exec "$@"
31 changes: 22 additions & 9 deletions 9.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ file_env() {
unset "$fileVar"
}

# Execute scripts from a given folder
# usage: exec_scripts FOLDER
exec_scripts() {
local execDir="$1"
local fileList=(${execDir}/*)
if [ ${#fileList[@]} -gt 0 ]; then
echo
for f in "${fileList[@]}"; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
fi
}

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
Expand All @@ -37,6 +56,7 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec_scripts "/docker-entrypoint-preexec.d"
exec gosu postgres "$BASH_SOURCE" "$@"
fi

Expand Down Expand Up @@ -110,15 +130,7 @@ if [ "$1" = 'postgres' ]; then
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
exec_scripts "/docker-entrypoint-initdb.d"

PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop
Expand All @@ -129,4 +141,5 @@ if [ "$1" = 'postgres' ]; then
fi
fi

exec_scripts "/docker-entrypoint-preexec.d"
exec "$@"
31 changes: 22 additions & 9 deletions 9.6/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ file_env() {
unset "$fileVar"
}

# Execute scripts from a given folder
# usage: exec_scripts FOLDER
exec_scripts() {
local execDir="$1"
local fileList=(${execDir}/*)
if [ ${#fileList[@]} -gt 0 ]; then
echo
for f in "${fileList[@]}"; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
fi
}

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
Expand All @@ -37,6 +56,7 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec_scripts "/docker-entrypoint-preexec.d"
exec gosu postgres "$BASH_SOURCE" "$@"
fi

Expand Down Expand Up @@ -110,15 +130,7 @@ if [ "$1" = 'postgres' ]; then
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
exec_scripts "/docker-entrypoint-initdb.d"

PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop
Expand All @@ -129,4 +141,5 @@ if [ "$1" = 'postgres' ]; then
fi
fi

exec_scripts "/docker-entrypoint-preexec.d"
exec "$@"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2015, Docker PostgreSQL Authors (See AUTHORS)
Copyright (c) 2014-2017, Docker PostgreSQL Authors (See AUTHORS)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
31 changes: 22 additions & 9 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ file_env() {
unset "$fileVar"
}

# Execute scripts from a given folder
# usage: exec_scripts FOLDER
exec_scripts() {
local execDir="$1"
local fileList=(${execDir}/*)
if [ ${#fileList[@]} -gt 0 ]; then
echo
for f in "${fileList[@]}"; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
fi
}

if [ "${1:0:1}" = '-' ]; then
set -- postgres "$@"
fi
Expand All @@ -37,6 +56,7 @@ if [ "$1" = 'postgres' ] && [ "$(id -u)" = '0' ]; then
chown -R postgres /var/run/postgresql
chmod g+s /var/run/postgresql

exec_scripts "/docker-entrypoint-preexec.d"
exec gosu postgres "$BASH_SOURCE" "$@"
fi

Expand Down Expand Up @@ -110,15 +130,7 @@ if [ "$1" = 'postgres' ]; then
psql+=( --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" )

echo
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; "${psql[@]}" -f "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${psql[@]}"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
exec_scripts "/docker-entrypoint-initdb.d"

PGUSER="${PGUSER:-postgres}" \
pg_ctl -D "$PGDATA" -m fast -w stop
Expand All @@ -129,4 +141,5 @@ if [ "$1" = 'postgres' ]; then
fi
fi

exec_scripts "/docker-entrypoint-preexec.d"
exec "$@"