summaryrefslogtreecommitdiffstats
path: root/Services/postgres
diff options
context:
space:
mode:
Diffstat (limited to 'Services/postgres')
-rw-r--r--Services/postgres/Dockerfile6
-rw-r--r--Services/postgres/README.md16
-rw-r--r--Services/postgres/docker-compose.yml4
-rw-r--r--Services/postgres/run.sh48
4 files changed, 42 insertions, 32 deletions
diff --git a/Services/postgres/Dockerfile b/Services/postgres/Dockerfile
index 701c127..9eee587 100644
--- a/Services/postgres/Dockerfile
+++ b/Services/postgres/Dockerfile
@@ -5,9 +5,9 @@ USER root
RUN dnf -y install postgresql postgresql-libs postgresql-server \
&& dnf clean all && \
mkdir -p /tmp/sql
-ENV STARTUPLOG=/data/logs/postgresql/startup.log \
- LOG_PATH=/data/logs/postgresql \
- DATA_PATH=/data/postgresql \
+ENV STARTUPLOG=/logs/startup.log \
+ LOG_PATH=/logs \
+ DATA_PATH=/data \
LOADSQL_PATH=/tmp/sql
COPY *.sh /bin/
COPY *.sql $LOADSQL_PATH/
diff --git a/Services/postgres/README.md b/Services/postgres/README.md
index d801d74..47eba27 100644
--- a/Services/postgres/README.md
+++ b/Services/postgres/README.md
@@ -35,8 +35,8 @@ service:
POSTGRESQL_PASSWORD: "pwd-test"
POSTGRESQL_DATABASE: "db_test"
volumes:
- - "/tmp/container/logs/postgres:/data/logs/postgres"
- - "/tmp/container/postgres:/data/postgres"
+ - "/tmp/container/logs/postgres:/logs"
+ - "/tmp/container/postgres:/data"
```
## Docker-compose in various situations
@@ -99,8 +99,8 @@ CMD ["/bin/run.sh"]
| POSTGRESQL_DATABASE | `string` | `no` | If present, add a new database with this name
| LOADSQL_PATH | `string` | `auto` | Path used to find sql dump to import at startup
| HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup
-| LOG_PATH | `auto` | `auto` | default set to /data/logs/postgres and used as a volume mountpoint
-| DATA_PATH | `auto` | `auto` | default set to /data/postgres and used as a volume mountpoint
+| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint
+| DATA_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint
## Exposed port
@@ -112,8 +112,8 @@ CMD ["/bin/run.sh"]
| Container directory | Description |
|----------------------|--------------------------------------------------------------------------|
-| /data/logs/postgres | log directory used to record container and postgres logs
-| /data/postgres | data directory served by postgres. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes
+| /logs | log directory used to record container and postgres logs
+| /data | data directory served by postgres. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes
## Testing the service
@@ -134,8 +134,8 @@ You must have a working environment with the source code of this repository. Rea
1. Jump into the container directory with `cd Services/postgres`
2. Build the container using `docker build -t sv-postgres .`
3. Run this container
- 1. Interactively with `docker run -p 5432:5432 -v /data/logs/postgres -it sv-postgres`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...)
- 2. As a daemon with `docker run -p 5432:5432 -v /data/logs/postgres -d sv-postgres`
+ 1. Interactively with `docker run -p 5432:5432 -v /logs -it sv-postgres`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...)
+ 2. As a daemon with `docker run -p 5432:5432 -v /logs -d sv-postgres`
### Build & run a container using `docker-compose`
diff --git a/Services/postgres/docker-compose.yml b/Services/postgres/docker-compose.yml
index 5dd37c9..d16ed2a 100644
--- a/Services/postgres/docker-compose.yml
+++ b/Services/postgres/docker-compose.yml
@@ -16,5 +16,5 @@ server:
POSTGRESQL_PASSWORD: "pwd-test"
POSTGRESQL_DATABASE: "db_test"
volumes:
- - "/tmp/container/logs/postgresql:/data/logs/postgresql"
- - "/tmp/container/postgresql:/data/postgresql" \ No newline at end of file
+ - "/tmp/container/logs/postgresql:/logs"
+ - "/tmp/container/postgresql:/data" \ No newline at end of file
diff --git a/Services/postgres/run.sh b/Services/postgres/run.sh
index 1c5436d..baea45c 100644
--- a/Services/postgres/run.sh
+++ b/Services/postgres/run.sh
@@ -13,11 +13,11 @@ set_listen_addresses() {
function check_postgresql_environment {
check_environment
if [ ! -v DATA_PATH ]; then
- DATA_PATH="/data/postgresql"
+ DATA_PATH="/data"
export DATA_PATH
fi
if [ ! -v LOG_PATH ]; then
- LOG_PATH="/data/logs/postgresql"
+ LOG_PATH="/logs"
export LOG_PATH
fi
}
@@ -92,6 +92,12 @@ function begin_config {
echo "Installing PostgreSQL in $DATA_PATH is DONE !"
chown root:postgres $STARTUPLOG
chmod ug+w $STARTUPLOG
+ config_startserver
+ config_createadmin
+ config_createuser
+ config_createdatabase
+ config_importsql
+ config_stopserver
fi
}
@@ -203,29 +209,33 @@ function end_config {
echo "=> END POSTGRESQL CONFIGURATION"
}
+function stop_postgres_handler {
+ su - postgres -c "pg_ctl -D $DATA_PATH -m fast -w stop"
+ set_listen_addresses '*'
+ sleep 2
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ exit 143; # 128 + 15 -- SIGTERM
+}
+
# Start the postgresql server as a deamon and execute it inside
# the running shell
-function start_daemon {
- echo "=> Starting postgresql daemon ..." | tee -a $STARTUPLOG
- display_container_started | tee -a $STARTUPLOG
- su - postgres -c "pg_ctl -D $DATA_PATH -w start "
- echo "postgres daemon is started" > /tmp/started
- exec tail -f /tmp/started
+function start_service_postgres {
+ trap 'kill ${!}; stop_postgres_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ su - postgres -c "pg_ctl -D $DATA_PATH -w start " &
+ while true
+ do
+ tail -f /dev/null & wait ${!}
+ done
}
-if [[ "$0" == *"run.sh" && ! $1 = "" ]];then
- eval "$@";
-fi
-
check_postgresql_environment | tee -a $STARTUPLOG
display_container_postgresql_header | tee -a $STARTUPLOG
begin_config | tee -a $STARTUPLOG
-config_startserver | tee -a $STARTUPLOG
-config_createadmin | tee -a $STARTUPLOG
-config_createuser | tee -a $STARTUPLOG
-config_createdatabase | tee -a $STARTUPLOG
-config_importsql | tee -a $STARTUPLOG
-config_stopserver | tee -a $STARTUPLOG
end_config | tee -a $STARTUPLOG
-start_daemon
+start_service_postgres