From 7c4611919af2ce635ca08f72c12df684d01fa912 Mon Sep 17 00:00:00 2001 From: Paul Caskey Date: Fri, 3 Mar 2017 14:23:04 -0600 Subject: [PATCH] initial add for instrumentation phase 1 --- Dockerfile | 10 +++++++++- files/bin/sendtierbeacon.sh | 25 +++++++++++++++++++++++++ files/bin/setenv.sh | 5 +++++ files/bin/startup.sh | 22 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 files/bin/sendtierbeacon.sh create mode 100644 files/bin/setenv.sh create mode 100644 files/bin/startup.sh diff --git a/Dockerfile b/Dockerfile index fada16b..f785421 100644 --- a/Dockerfile +++ b/Dockerfile @@ -138,4 +138,12 @@ RUN ln -s /opt/etc/httpd/conf.d/ports.conf /etc/httpd/conf.d/ports.conf && \ # Port EXPOSE 80 443 -CMD ["/opt/bin/start.sh"] +ADD files/bin/setenv.sh /opt/tier/setenv.sh +RUN chmod +x /opt/tier/setenv.sh +ADD files/bin/startup.sh /usr/bin/startup.sh +RUN chmod +x /usr/bin/startup.sh +ADD files/bin/sendtierbeacon.sh /usr/bin/sendtierbeacon.sh +RUN chmod +x /usr/bin/sendtierbeacon.sh + + +CMD ["/usr/bin/startup.sh"] diff --git a/files/bin/sendtierbeacon.sh b/files/bin/sendtierbeacon.sh new file mode 100644 index 0000000..f9ba5c4 --- /dev/null +++ b/files/bin/sendtierbeacon.sh @@ -0,0 +1,25 @@ +#!/bin/bash +LOGHOST="collector.testbed.tier.internet2.edu" +LOGPORT="5001" +if [ -s /opt/tier/env.bash ]; then + . /opt/tier/env.bash +fi + +#below for syslog, F-TICKS style +#LOGTEXT="TIERBEACON/TIER/1.0#IM=$IMAGENAME#PV=$VERSION#TR=$TIERVERSION#MT=$MAINTAINER#" + +#below for JSON/REST style +LOGTEXT="{ \"msgType\" : \"TIERBEACON\", \"msgName\" : \"TIER\", \"msgVersion\" : \"1.0\", \"tbProduct\" : \"$IMAGENAME\", \"tbProductVersion\" : \"$VERSION\", \"tbTIERRelease\" : \"$TIERVERSION\", \"tbMaintainer\" : \"$MAINTAINER\" }" + + +if [ -z "$TIER_BEACON_OPT_OUT" ]; then + #send JSON + echo $LOGTEXT > msgjson.txt + curl -s -XPOST "${LOGHOST}:${LOGPORT}/" -H 'Content-Type: application/json' -T msgjson.txt 1>/dev/null + rm -f msgjson.txt + + #below is for syslog, F-TICKS style + #`logger -n $LOGHOST -P $LOGPORT -t TIERBEACON $LOGTEXT` + + echo `date`"; TIER beacon sent." +fi diff --git a/files/bin/setenv.sh b/files/bin/setenv.sh new file mode 100644 index 0000000..a43bc0b --- /dev/null +++ b/files/bin/setenv.sh @@ -0,0 +1,5 @@ +#!/bin/bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^VERSION" > /opt/tier/env.bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^TIERVERSION" >> /opt/tier/env.bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^IMAGE" >> /opt/tier/env.bash +printenv | sed 's/^\(.*\)$/\1/g' | grep -E "^MAINTAINER" >> /opt/tier/env.bash diff --git a/files/bin/startup.sh b/files/bin/startup.sh new file mode 100644 index 0000000..c3bb95d --- /dev/null +++ b/files/bin/startup.sh @@ -0,0 +1,22 @@ +#!/bin/bash +CRONFILE=/opt/tier/tier-cron + +#set env vars for cron job +/opt/tier/setenv.sh + +#build crontab file with random start time between midnight and 3:59am +echo "#send daily beacon to TIER Central" > ${CRONFILE} +echo $(expr $RANDOM % 59) $(expr $RANDOM % 3) "* * * /usr/bin/sendtierbeacon.sh >> /var/log/cron.log 2>&1" >> ${CRONFILE} +chmod 644 ${CRONFILE} + +#install crontab +crontab ${CRONFILE} + +#create cron logfile +touch /var/log/cron.log + +#start crond +/usr/sbin/crond + +#from intermediate container's CMD directive +/opt/bin/start.sh