entrypoint.sh 1.36 KB
Newer Older
PICHOU Kyâne's avatar
PICHOU Kyâne committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

# if wal backup is not enabled, use minimal wal logging to reduce disk space
: ${WAL_LEVEL:=minimal}
: ${ARCHIVE_MODE:=off}
: ${ARCHIVE_TIMEOUT:=60}

export WAL_LEVEL
export ARCHIVE_MODE
export ARCHIVE_TIMEOUT

# PGDATA is defined in upstream postgres dockerfile

function update_conf () {
    if [ -f $PGDATA/postgresql.conf ]; then
        sed -i "s/wal_level =.*$/wal_level = $WAL_LEVEL/g" $PGDATA/postgresql.conf
        sed -i "s/archive_mode =.*$/archive_mode = $ARCHIVE_MODE/g" $PGDATA/postgresql.conf
        sed -i "s/archive_timeout =.*$/archive_timeout = $ARCHIVE_TIMEOUT/g" $PGDATA/postgresql.conf
    fi
}

if [ "${1:0:1}" = '-'  ]; then
    set -- postgres "$@"
fi

if [ "$1" = 'postgres'  ]; then
    VARS=(AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY WALE_S3_PREFIX AWS_REGION)

    for v in ${VARS[@]}; do
        if [ "${!v}" = "" ]; then
            echo "$v is required for Wal-E but not set. Skipping Wal-E setup."
            update_conf
PICHOU Kyâne's avatar
PICHOU Kyâne committed
33
            # Run the postgresql entrypoint
PICHOU Kyâne's avatar
PICHOU Kyâne committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
            . /docker-entrypoint.sh
            exit
        fi
    done

    umask u=rwx,g=rx,o=
    mkdir -p /etc/wal-e.d/env

    for v in ${VARS[@]}; do
        echo "${!v}" > /etc/wal-e.d/env/$v
    done
    chown -R root:postgres /etc/wal-e.d

    WAL_LEVEL=archive
    ARCHIVE_MODE=on

    update_conf
PICHOU Kyâne's avatar
PICHOU Kyâne committed
51
    # Run the postgresql entrypoint
PICHOU Kyâne's avatar
PICHOU Kyâne committed
52
53
    . /docker-entrypoint.sh
fi