-
Notifications
You must be signed in to change notification settings - Fork 105
/
start.sh
34 lines (30 loc) · 932 Bytes
/
start.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
#!/bin/bash
set -e
: ${S3_PATH:?"S3_PATH env variable is required"}
export DATA_PATH=${DATA_PATH:-/data/}
CRON_SCHEDULE=${CRON_SCHEDULE:-0 1 * * *}
if [[ -n "$ACCESS_KEY" && -n "$SECRET_KEY" ]]; then
echo "access_key=$ACCESS_KEY" >> /root/.s3cfg
echo "secret_key=$SECRET_KEY" >> /root/.s3cfg
else
echo "No ACCESS_KEY and SECRET_KEY env variable found, assume use of IAM"
fi
if [[ "$1" == 'no-cron' ]]; then
exec /sync.sh
elif [[ "$1" == 'get' ]]; then
exec /get.sh
elif [[ "$1" == 'delete' ]]; then
exec /usr/local/bin/s3cmd del -r "$S3_PATH"
else
LOGFIFO='/var/log/cron.fifo'
if [[ ! -e "$LOGFIFO" ]]; then
mkfifo "$LOGFIFO"
fi
CRON_ENV="PARAMS='$PARAMS'"
CRON_ENV="$CRON_ENV\nDATA_PATH='$DATA_PATH'"
CRON_ENV="$CRON_ENV\nS3_PATH='$S3_PATH'"
echo -e "$CRON_ENV\n$CRON_SCHEDULE /sync.sh > $LOGFIFO 2>&1" | crontab -
crontab -l
cron
tail -f "$LOGFIFO"
fi