forked from citusdata/podyn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
62 lines (51 loc) · 2.02 KB
/
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
#!/bin/bash
if [[ -n $DYNAMODB_ENDPOINT ]]; then
DYNAMODB_OPTS="--ddb-endpoint \"$DYNAMODB_ENDPOINT\""
else
DYNAMODB_OPTS=""
fi
PODYN=$@
if [[ "$@" != "--"* ]]; then
SLACK=`echo $@ | sed 's/ .*//'`
PODYN=`echo $@ | sed 's/.* //'`
fi
echo "Slack: $SLACK"
echo "Podyn: $PODYN"
# Create a launcher script to stop a running podyn and start a new one
echo "#!/bin/bash" > ./launch.sh
echo "export AWS_SECRET_ACCESS_KEY=\"$AWS_SECRET_ACCESS_KEY\"" >> ./launch.sh
echo "export AWS_ACCESS_KEY_ID=\"$AWS_ACCESS_KEY_ID\"" >> ./launch.sh
echo "export AWS_REGION=\"$AWS_REGION\"" >> ./launch.sh
echo "" >> ./launch.sh
echo "if ps aux | grep -v \"grep\" | grep \"podyn.jar\"" >> ./launch.sh
echo "then" >> ./launch.sh
echo " echo \"podyn.jar is already running\"" >> ./launch.sh
echo "else" >> ./launch.sh
echo " echo \"starting podyn.jar ${@} &>> /app/podyn.log\"" >> ./launch.sh
echo " java -jar /app/podyn.jar --postgres-jdbc-url \"${POSTGRES_JDBC_URL}\" $DYNAMODB_OPTS ${@} &>> /app/podyn.log &" >> ./launch.sh
echo " if [ \"$SLACK\" != \"\" ]; then" >> ./launch.sh
echo " curl -X POST --data-urlencode 'payload={\"username\":\"podyn\",\"channel\":\"developers\",\"icon_url\":\"\",\"attachments\":[{\"color\":\"#4183c4\",\"text\":\"Launching podyn ${AWS_REGION}\",\"footer\":\"\"}]}' $SLACK" >> ./launch.sh
echo " fi" >> ./launch.sh
echo "fi" >> ./launch.sh
chmod +x ./launch.sh
echo "---- env"
env
echo "----"
if [[ ${@} != *"--data"* ]]; then
# Start the syncer
rm -f /app/podyn.log
touch /app/podyn.log
service rsyslog start
service cron start
crontab -l
echo "Podyn SYNC" >> /app/podyn.log
/app/launch.sh
# tail -f /var/log/syslog | xargs -IL date +"SYSLOG: %Y-%m-%d %H:%M:%S - L"
tail -f /app/podyn.log | xargs -IL date +"PODYN: %Y-%m-%d %H:%M:%S - L"
else
# Just load the data and exit
service cron stop
echo "Podyn COPY" >> /app/podyn.log
java -jar /app/podyn.jar --postgres-jdbc-url "${POSTGRES_JDBC_URL}" $DYNAMODB_OPTS ${@}
fi
echo "entrypoint terminated with $?"