-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker-entrypoint.sh
58 lines (51 loc) · 1.98 KB
/
docker-entrypoint.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Logic for Password file required
# If PASSWORD_SECRET env var is defined, search for the /run/secrets/${PASSWORD_SECRET} and read the content
# If PASSWORD_SECRET is not defined, use PASSWORD env variable
# The idea, as specified in the software:
# create a file $HOME/.pgpass containing a line like this
# hostname:*:*:dbuser:dbpass
# replace hostname with the value of DBHOST and postgres with
# the value of USERNAME
PASSPHRASE=""
if [ "${PASSWORD_SECRET}" ]; then
echo "Using docker secrets..."
if [ -f "/run/secrets/${PASSWORD_SECRET}" ]; then
PASSPHRASE=$(cat /run/secrets/${PASSWORD_SECRET})
else
echo "ERROR: Secret file not found in /run/secrets/${PASSWORD_SECRET}"
echo "Please verify your docker secrets configuration."
exit 1
fi
else
echo "Using environment password..."
PASSPHRASE=${PASSWORD}
fi
# Logic for the CRON schedule
# If CRON_SCHEDULE is defined, delete the script under cron.daily and copy this one to crontab
# If CRON_SCHEDULE is not defined, don't do anything, use default cron.daily behaviour
if [ "${CRON_SCHEDULE}" ]; then
echo "Configuring a CUSTOM SCHEDULE in /etc/crontab for ${CRON_SCHEDULE} ..."
# Create the crontab file
cat <<-EOF > /etc/crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
${CRON_SCHEDULE} /usr/sbin/autopostgresqlbackup
EOF
crontab /etc/crontab
else
echo "Using cron.daily schedule..."
echo -e "#!/bin/bash\n/usr/sbin/autopostgresqlbackup" > /etc/periodic/daily/backup.sh
chmod +x /etc/periodic/daily/backup.sh
fi
# Create the file
echo "Creating the password file..."
cat <<-EOF > ${HOME}/.pgpass
${DBHOST:-localhost}:*:*:${USERNAME:-postgres}:${PASSPHRASE}
EOF
# Permissions for this file shoudl be set to 0600
chmod 0600 ${HOME}/.pgpass
# Execute cron with parameters (autopostgresql script is under /etc/cron.daily)
echo "Execute cron service..."
exec crond -f -l ${CRON_LOG_LEVEL:-8}