From a696cba95484f605c2931a6f6e81292a0b463eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 7 Nov 2026 11:37:01 +0000 Subject: [PATCH] Support PostgreSQL and make the setup timeout configurable Running the images against PostgreSQL never worked (akaunting/akaunting#3414): - The Debian images compiled pdo_mysql but not pdo_pgsql, and the Alpine images installed the plain pgsql extension, which Laravel cannot use. pdo_pgsql is now built in all seven images. - Setup gave up after 30 seconds, which is too short for a database that starts slowly, e.g. on Kubernetes. AKAUNTING_SETUP_TIMEOUT and AKAUNTING_SETUP_RETRY_INTERVAL now control this, with the old values as defaults. The retry loop also never printed "Unable to find database!": under bash -e, `(( retry_for -= retry_interval ))` reaching 0 returned 1 and ended the script first. The decrement is now an assignment. The number of attempts and the exit code are unchanged. Existing MySQL/MariaDB installations behave exactly as before. Refs akaunting/akaunting#3414, akaunting/akaunting#3422 --- Dockerfile | 1 + README.md | 16 ++++++++++++++++ env/run.env.example | 8 ++++++++ files/akaunting-php-fpm-nginx-supervisord.sh | 12 ++++++++---- files/akaunting-php-fpm-nginx.sh | 12 ++++++++---- files/akaunting-php-fpm.sh | 12 ++++++++---- files/akaunting-v.sh | 12 ++++++++---- files/akaunting.sh | 12 ++++++++---- fpm-alpine-nginx-composer-supervisor.Dockerfile | 2 +- fpm-alpine-nginx-composer.Dockerfile | 2 +- fpm-alpine-nginx.Dockerfile | 2 +- fpm-alpine.Dockerfile | 2 +- fpm.Dockerfile | 1 + v.Dockerfile | 1 + 14 files changed, 71 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7454b05..c329029 100644 --- a/Dockerfile +++ b/Dockerfile @@ -43,6 +43,7 @@ RUN docker-php-ext-configure gd \ pcntl \ pdo \ pdo_mysql \ + pdo_pgsql \ zip RUN mkdir -p /var/www/akaunting \ diff --git a/README.md b/README.md index a85503a..17003f4 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,22 @@ DB_HOST_WRITE: "example-write" DB_HOST_READ: "example-read" ``` +To use PostgreSQL instead of MySQL/MariaDB, point the `DB_*` variables at your PostgreSQL server and set the driver: + +``` +# In env/run.env put: +DB_CONNECTION=pgsql +DB_PORT=5432 +``` + +During setup the container retries the installation for 30 seconds, every 5 seconds, until the database is reachable, and then exits with `Unable to find database!`. If your database takes longer to start (for example on Kubernetes), raise the timeout: + +``` +# In env/run.env put: +AKAUNTING_SETUP_TIMEOUT=300 +AKAUNTING_SETUP_RETRY_INTERVAL=10 +``` + You can use Redis with Akaunting for performance enhancement and scalability, if you have a Redis you can take advantage of the following environment variables: ``` diff --git a/env/run.env.example b/env/run.env.example index 78182de..06461c8 100644 --- a/env/run.env.example +++ b/env/run.env.example @@ -11,6 +11,9 @@ DB_NAME=akaunting DB_USERNAME=admin DB_PASSWORD=akaunting_password +# For PostgreSQL instead of MySQL/MariaDB, uncomment this and set DB_PORT to 5432 +#DB_CONNECTION=pgsql + # You should change this to a random string of three numbers or letters followed by an underscore DB_PREFIX=asd_ @@ -21,3 +24,8 @@ COMPANY_EMAIL=my@company.com # This will be the first administrative user created on setup. ADMIN_EMAIL=me@company.com ADMIN_PASSWORD=password + +# How long setup keeps retrying while the database is not reachable yet, and the wait between attempts (in seconds). +# Raise the timeout if your database takes longer to start, e.g. on Kubernetes. +#AKAUNTING_SETUP_TIMEOUT=30 +#AKAUNTING_SETUP_RETRY_INTERVAL=5 diff --git a/files/akaunting-php-fpm-nginx-supervisord.sh b/files/akaunting-php-fpm-nginx-supervisord.sh index 30d9cc2..f6c5771 100755 --- a/files/akaunting-php-fpm-nginx-supervisord.sh +++ b/files/akaunting-php-fpm-nginx-supervisord.sh @@ -4,8 +4,12 @@ mkdir -p storage/framework/{sessions,views,cache} mkdir -p storage/app/uploads if [ "$AKAUNTING_SETUP" == "true" ]; then - retry_for=30 - retry_interval=5 + retry_for="${AKAUNTING_SETUP_TIMEOUT:-30}" + retry_interval="${AKAUNTING_SETUP_RETRY_INTERVAL:-5}" + if ! [[ "$retry_for" =~ ^[0-9]+$ && "$retry_interval" =~ ^[1-9][0-9]*$ ]]; then + echo "AKAUNTING_SETUP_TIMEOUT and AKAUNTING_SETUP_RETRY_INTERVAL must be whole numbers of seconds (interval greater than 0)." >&2 + exit 1 + fi while sleep $retry_interval; do if php artisan install \ --db-host=$DB_HOST \ @@ -20,11 +24,11 @@ if [ "$AKAUNTING_SETUP" == "true" ]; then "--admin-password=$ADMIN_PASSWORD" \ "--locale=$LOCALE" --no-interaction; then break else - if [ $retry_for -le 0 ]; then + retry_for=$(( retry_for - retry_interval )) + if [ "$retry_for" -le 0 ]; then echo "Unable to find database!" >&2 exit 1 fi - (( retry_for -= retry_interval )) fi done else diff --git a/files/akaunting-php-fpm-nginx.sh b/files/akaunting-php-fpm-nginx.sh index 8bf3df0..f6065a3 100755 --- a/files/akaunting-php-fpm-nginx.sh +++ b/files/akaunting-php-fpm-nginx.sh @@ -25,8 +25,12 @@ mkdir -p storage/framework/{sessions,views,cache} mkdir -p storage/app/uploads if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then - retry_for=30 - retry_interval=5 + retry_for="${AKAUNTING_SETUP_TIMEOUT:-30}" + retry_interval="${AKAUNTING_SETUP_RETRY_INTERVAL:-5}" + if ! [[ "$retry_for" =~ ^[0-9]+$ && "$retry_interval" =~ ^[1-9][0-9]*$ ]]; then + echo "AKAUNTING_SETUP_TIMEOUT and AKAUNTING_SETUP_RETRY_INTERVAL must be whole numbers of seconds (interval greater than 0)." >&2 + exit 1 + fi while sleep $retry_interval; do if php artisan install \ --db-host=$DB_HOST \ @@ -41,11 +45,11 @@ if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then "--admin-password=$ADMIN_PASSWORD" \ "--locale=$LOCALE" --no-interaction; then break else - if [ $retry_for -le 0 ]; then + retry_for=$(( retry_for - retry_interval )) + if [ "$retry_for" -le 0 ]; then echo "Unable to find database!" >&2 exit 1 fi - (( retry_for -= retry_interval )) fi done else diff --git a/files/akaunting-php-fpm.sh b/files/akaunting-php-fpm.sh index 9a0cc84..e06c76a 100755 --- a/files/akaunting-php-fpm.sh +++ b/files/akaunting-php-fpm.sh @@ -25,8 +25,12 @@ mkdir -p storage/framework/{sessions,views,cache} mkdir -p storage/app/uploads if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then - retry_for=30 - retry_interval=5 + retry_for="${AKAUNTING_SETUP_TIMEOUT:-30}" + retry_interval="${AKAUNTING_SETUP_RETRY_INTERVAL:-5}" + if ! [[ "$retry_for" =~ ^[0-9]+$ && "$retry_interval" =~ ^[1-9][0-9]*$ ]]; then + echo "AKAUNTING_SETUP_TIMEOUT and AKAUNTING_SETUP_RETRY_INTERVAL must be whole numbers of seconds (interval greater than 0)." >&2 + exit 1 + fi while sleep $retry_interval; do if php artisan install \ --db-host=$DB_HOST \ @@ -41,11 +45,11 @@ if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then "--admin-password=$ADMIN_PASSWORD" \ "--locale=$LOCALE" --no-interaction; then break else - if [ $retry_for -le 0 ]; then + retry_for=$(( retry_for - retry_interval )) + if [ "$retry_for" -le 0 ]; then echo "Unable to find database!" >&2 exit 1 fi - (( retry_for -= retry_interval )) fi done else diff --git a/files/akaunting-v.sh b/files/akaunting-v.sh index 8b16bba..e28fcd0 100755 --- a/files/akaunting-v.sh +++ b/files/akaunting-v.sh @@ -34,8 +34,12 @@ mkdir -p storage/framework/{sessions,views,cache} mkdir -p storage/app/uploads if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then - retry_for=30 - retry_interval=5 + retry_for="${AKAUNTING_SETUP_TIMEOUT:-30}" + retry_interval="${AKAUNTING_SETUP_RETRY_INTERVAL:-5}" + if ! [[ "$retry_for" =~ ^[0-9]+$ && "$retry_interval" =~ ^[1-9][0-9]*$ ]]; then + echo "AKAUNTING_SETUP_TIMEOUT and AKAUNTING_SETUP_RETRY_INTERVAL must be whole numbers of seconds (interval greater than 0)." >&2 + exit 1 + fi if [[ -z "${DB_HOST_WRITE}" ]]; then db_host="${DB_HOST}" @@ -58,11 +62,11 @@ if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then "--admin-password=$ADMIN_PASSWORD" \ "--locale=$LOCALE" --no-interaction; then break else - if [ $retry_for -le 0 ]; then + retry_for=$(( retry_for - retry_interval )) + if [ "$retry_for" -le 0 ]; then echo "Unable to find database!" >&2 exit 1 fi - (( retry_for -= retry_interval )) fi done else diff --git a/files/akaunting.sh b/files/akaunting.sh index 3711072..b0abdf3 100755 --- a/files/akaunting.sh +++ b/files/akaunting.sh @@ -27,8 +27,12 @@ mkdir -p storage/framework/{sessions,views,cache} mkdir -p storage/app/uploads if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then - retry_for=30 - retry_interval=5 + retry_for="${AKAUNTING_SETUP_TIMEOUT:-30}" + retry_interval="${AKAUNTING_SETUP_RETRY_INTERVAL:-5}" + if ! [[ "$retry_for" =~ ^[0-9]+$ && "$retry_interval" =~ ^[1-9][0-9]*$ ]]; then + echo "AKAUNTING_SETUP_TIMEOUT and AKAUNTING_SETUP_RETRY_INTERVAL must be whole numbers of seconds (interval greater than 0)." >&2 + exit 1 + fi while sleep $retry_interval; do if php artisan install \ --db-host=$DB_HOST \ @@ -43,11 +47,11 @@ if [ "$do_setup" -o "$AKAUNTING_SETUP" == "true" ]; then "--admin-password=$ADMIN_PASSWORD" \ "--locale=$LOCALE" --no-interaction; then break else - if [ $retry_for -le 0 ]; then + retry_for=$(( retry_for - retry_interval )) + if [ "$retry_for" -le 0 ]; then echo "Unable to find database!" >&2 exit 1 fi - (( retry_for -= retry_interval )) fi done else diff --git a/fpm-alpine-nginx-composer-supervisor.Dockerfile b/fpm-alpine-nginx-composer-supervisor.Dockerfile index 07015b0..4273b57 100644 --- a/fpm-alpine-nginx-composer-supervisor.Dockerfile +++ b/fpm-alpine-nginx-composer-supervisor.Dockerfile @@ -31,7 +31,7 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do # Install PHP Extensions RUN chmod +x /usr/local/bin/install-php-extensions && sync && \ - install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql redis + install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql pdo_pgsql redis # Configure Extension RUN docker-php-ext-configure \ diff --git a/fpm-alpine-nginx-composer.Dockerfile b/fpm-alpine-nginx-composer.Dockerfile index a639b6d..6782381 100644 --- a/fpm-alpine-nginx-composer.Dockerfile +++ b/fpm-alpine-nginx-composer.Dockerfile @@ -30,7 +30,7 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do # Install PHP Extensions RUN chmod +x /usr/local/bin/install-php-extensions && sync && \ - install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql redis + install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql pdo_pgsql redis # Configure Extension RUN docker-php-ext-configure \ diff --git a/fpm-alpine-nginx.Dockerfile b/fpm-alpine-nginx.Dockerfile index f76e1cc..12dfa28 100644 --- a/fpm-alpine-nginx.Dockerfile +++ b/fpm-alpine-nginx.Dockerfile @@ -19,7 +19,7 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do # Install PHP Extensions RUN chmod +x /usr/local/bin/install-php-extensions && sync && \ - install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql + install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql pdo_pgsql # Configure Extension RUN docker-php-ext-configure \ diff --git a/fpm-alpine.Dockerfile b/fpm-alpine.Dockerfile index c854806..369c11b 100644 --- a/fpm-alpine.Dockerfile +++ b/fpm-alpine.Dockerfile @@ -35,7 +35,7 @@ ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/do # Install PHP Extensions RUN chmod +x /usr/local/bin/install-php-extensions && sync && \ - install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql redis pcntl + install-php-extensions gd zip intl imap xsl pgsql opcache bcmath mysqli pdo_mysql pdo_pgsql redis pcntl # Configure Extension RUN docker-php-ext-configure \ diff --git a/fpm.Dockerfile b/fpm.Dockerfile index 0a1796d..cee51ac 100644 --- a/fpm.Dockerfile +++ b/fpm.Dockerfile @@ -44,6 +44,7 @@ RUN docker-php-ext-configure gd \ pcntl \ pdo \ pdo_mysql \ + pdo_pgsql \ zip # Download Akaunting application diff --git a/v.Dockerfile b/v.Dockerfile index c977e55..e679b4f 100644 --- a/v.Dockerfile +++ b/v.Dockerfile @@ -43,6 +43,7 @@ RUN docker-php-ext-configure gd \ pcntl \ pdo \ pdo_mysql \ + pdo_pgsql \ zip RUN pecl install redis && docker-php-ext-enable redis