-
Notifications
You must be signed in to change notification settings - Fork 19
/
docker-entrypoint.sh
86 lines (63 loc) · 1.72 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Create mail config if defined
if [[ $SMTP_HOST ]]; then
if [[ $SMTP_TLS = "on" ]]; then
# Configuration with TLS
cat << EOF > /etc/msmtprc
defaults
host $SMTP_HOST
port $SMTP_PORT
tls $SMTP_TLS
tls_starttls $SMTP_TLS
tls_trust_file /etc/ssl/certs/ca-certificates.crt
tls_certcheck $SMTP_TLS
account $SMTP_USER
auth $SMTP_AUTH
user $SMTP_USER
password "$SMTP_PASS"
from "$SMTP_USER"
account default: $SMTP_USER
aliases /etc/aliases
EOF
else
# Configuration without TLS
cat << EOF > /etc/msmtprc
defaults
host $SMTP_HOST
port $SMTP_PORT
account $SMTP_USER
auth $SMTP_AUTH
user $SMTP_USER
password "$SMTP_PASS"
from "$SMTP_USER"
account default: $SMTP_USER
aliases /etc/aliases
EOF
fi
cat << EOF > /etc/aliases
root: $SMTP_FROM
default: $SMTP_FROM
EOF
echo 'set sendmail="/usr/bin/msmtp -t"' > /etc/mail.rc
fi
# Store environment variables to pass to cron job
printenv | sed 's/^\([a-zA-Z0-9_]*\)=\(.*\)$/export \1="\2"/g' > /container_env.sh
# Remove quotes from CRON_SCHEDULE
cronSchedule=${CRON_SCHEDULE}
cronSchedule=${cronSchedule%\"}
cronSchedule=${cronSchedule#\"}
# Write log to stdout
cronLogConfig="> /proc/1/fd/1 2>&1 | tee -a $cronLogFile"
# Create crontab definition
if [[ $SMTP_HOST ]];
then
echo "Cron e-mail reporting activated. '${SMTP_HOST}'"
echo "$cronSchedule . /container_env.sh; /usr/local/bin/backup.sh $cronLogConfig | mail -s 'SQL Server Backup Result' $MAIL_TO $cronLogConfig" > /etc/cron.d/crontab.conf
else
echo "$cronSchedule . /container_env.sh; /usr/local/bin/backup.sh $cronLogConfig" > /etc/cron.d/crontab.conf
fi
# Apply cron job
crontab /etc/cron.d/crontab.conf
echo "Starting cron task manager..."
echo " - Crontab = $cronSchedule"
cron -f