Database configuration should be set properly when using sqlite. (#78)

This will fix the default settings for sqlite database when running mailman-core image.
This commit is contained in:
Abhilash Raj
2017-07-20 15:01:23 -07:00
committed by GitHub
parent fb5b8c8410
commit 84dac7ae42
2 changed files with 52 additions and 32 deletions

View File

@@ -22,34 +22,13 @@ function wait_for_postgres () {
>&2 echo "Postgres is up - continuing"
}
# Check if $DATABASE_URL is defined, if not, use a standard sqlite database.
#
# If the $DATABASE_URL is defined and is postgres, check if it is available
# yet. Do not start the container before the postgresql boots up.
#
# TODO: If the $DATABASE_URL is defined and is mysql, check if the database is
# available before the container boots up.
#
# TODO: Check the database type and detect if it is up based on that. For now,
# assume that postgres is being used if DATABASE_URL is defined.
if [[ ! -v DATABASE_URL ]]; then
echo "DATABASE_URL is not defined. Using sqlite database..."
export DATABASE_URL=sqlite:///mailman.db
export DATABASE_TYPE='sqlite'
export DATABASE_CLASS='mailman.database.sqlite.SQLiteDatabase'
fi
if [[ "$DATABASE_TYPE" = 'postgres' ]]
then
wait_for_postgres
fi
# Empty the config file.
echo "# This file is autogenerated at container startup." > /etc/mailman.cfg
# Check if $MM_HOSTNAME is set, if not, set it to a default value.
# TODO: Factor this out to a function.
if [[ ! -v MM_HOSTNAME ]]; then
export MM_HOSTNAME=mailman-core
export MM_HOSTNAME='172.19.199.2'
fi
if [[ ! -v SMTP_HOST ]]; then
@@ -64,8 +43,46 @@ if [[ ! -v HYPERKITTY_URL ]]; then
export HYPERKITTY_URL=http://mailman-web:8000/
fi
function setup_database () {
if [[ ! -v DATABASE_URL ]]
then
echo "Environemnt variable DATABASE_URL should be defined..."
exit 1
fi
cat >> /etc/mailman.cfg <<EOF
[database]
class: $DATABASE_CLASS
url: $DATABASE_URL
EOF
}
# Check if $DATABASE_URL is defined, if not, use a standard sqlite database.
#
# If the $DATABASE_URL is defined and is postgres, check if it is available
# yet. Do not start the container before the postgresql boots up.
#
# TODO: If the $DATABASE_URL is defined and is mysql, check if the database is
# available before the container boots up.
#
# TODO: Check the database type and detect if it is up based on that. For now,
# assume that postgres is being used if DATABASE_URL is defined.
if [[ ! -v DATABASE_URL ]]; then
echo "DATABASE_URL is not defined. Using sqlite database..."
else
setup_database
fi
if [[ "$DATABASE_TYPE" = 'postgres' ]]
then
wait_for_postgres
fi
# Generate a basic mailman.cfg.
cat > /etc/mailman.cfg <<EOF
cat >> /etc/mailman.cfg <<EOF
[mta]
incoming: mailman.mta.exim4.LMTP
outgoing: mailman.mta.deliver.deliver
@@ -85,10 +102,6 @@ hostname: $MM_HOSTNAME
class: mailman_hyperkitty.Archiver
enable: yes
configuration: /etc/mailman-hyperkitty.cfg
[database]
class: $DATABASE_CLASS
url: $DATABASE_URL
EOF
# Generate a basic configuration to use postfix.