You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/10/11 17:11:17 UTC

[trafficcontrol] 07/21: Now executing packaged ORT script; moved crontab into ORT package

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 3ad1bba86423967cc25467ad18b0716f1996658f
Author: ocket8888 <Br...@comcast.com>
AuthorDate: Wed Oct 3 15:37:02 2018 +0000

    Now executing packaged ORT script; moved crontab into ORT package
---
 infrastructure/cdn-in-a-box/cache/Dockerfile           |  9 +++++----
 infrastructure/cdn-in-a-box/edge/run.sh                | 10 ++--------
 infrastructure/cdn-in-a-box/mid/run.sh                 | 10 ++--------
 infrastructure/cdn-in-a-box/ort/setup.py               |  7 ++-----
 .../{cache/crontab => ort/traffic_ops_ort.crontab}     |  2 +-
 infrastructure/cdn-in-a-box/traffic_ops/to-access.sh   | 18 +++++++++++++-----
 6 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/infrastructure/cdn-in-a-box/cache/Dockerfile b/infrastructure/cdn-in-a-box/cache/Dockerfile
index 5658434..5258b05 100644
--- a/infrastructure/cdn-in-a-box/cache/Dockerfile
+++ b/infrastructure/cdn-in-a-box/cache/Dockerfile
@@ -35,7 +35,7 @@ RUN pip3 install --upgrade pip && pip3 install requests urllib3 distro
 ADD traffic_server/plugins/astats_over_http/astats_over_http.c traffic_server/plugins/astats_over_http/Makefile.am /
 
 RUN tsxs -v -c astats_over_http.c -o astats_over_http.so
-RUN mkdir -p /usr/libexec/trafficserver && tsxs -v -o astats_over_http.so -i
+RUN mkdir -p /usr/libexec/trafficserver /opt/ort && tsxs -v -o astats_over_http.so -i
 
 RUN yum remove -y gcc-c++ glibc-devel autoconf automake libtool && rm -f /astats_over_http.c /Makefile.am
 
@@ -48,9 +48,10 @@ RUN mkdir -p /var/trafficserver /opt/ort && \
 
 RUN setcap CAP_NET_BIND_SERVICE=+eip /bin/traffic_server && setcap CAP_NET_BIND_SERVICE=+eip /bin/traffic_manager && setcap CAP_NET_BIND_SERVICE=+eip /bin/trafficserver && setcap CAP_NET_BIND_SERVICE=+eip /bin/traffic_cop
 
-ADD infrastructure/cdn-in-a-box/edge/traffic_ops_ort.py /opt/ort/
-ADD infrastructure/cdn-in-a-box/cache/crontab /etc/cron.d/traffic_ops_ort-cron-template
+ADD infrastructure/cdn-in-a-box/ort /opt/ort/
 
-RUN touch /var/log/ort.log
+WORKDIR /opt/ort
+
+RUN touch /var/log/ort.log && pip3 install . && cp traffic_ops_ort.crontab /etc/cron.d/traffic_ops_ort-cron-template
 
 CMD exit
diff --git a/infrastructure/cdn-in-a-box/edge/run.sh b/infrastructure/cdn-in-a-box/edge/run.sh
index d84e6d6..affb597 100755
--- a/infrastructure/cdn-in-a-box/edge/run.sh
+++ b/infrastructure/cdn-in-a-box/edge/run.sh
@@ -57,19 +57,13 @@ done
 
 to-enroll edge $CDN || (while true; do echo "enroll failed."; sleep 3 ; done)
 
-function testenrolled() {
-	local tmp="$(to-get	'api/1.3/servers?name=edge')"
-	tmp=$(echo $tmp | jq '.response[]|select(.hostName=="edge")')
-	echo "$tmp"
-}
-
 while [[ -z "$(testenrolled)" ]]; do
 	echo "waiting on enrollment"
 	sleep 3
 done
 
 # Leaves the container hanging open in the event of a failure for debugging purposes
-/opt/ort/traffic_ops_ort.py BADASS ALL "https://$TO_FQDN:$TO_PORT" "$TO_ADMIN_USER:$TO_ADMIN_PASSWORD" || { echo "Failed"; }
+traffic_ops_ort -k BADASS ALL "https://$TO_FQDN:$TO_PORT" "$TO_ADMIN_USER:$TO_ADMIN_PASSWORD" || { echo "Failed"; }
 
 envsubst < "/etc/cron.d/traffic_ops_ort-cron-template" > "/var/spool/cron/root" && rm -f "/etc/cron.d/traffic_ops_ort-cron-template"
 crontab "/var/spool/cron/root"
@@ -82,4 +76,4 @@ done
 crontab -r
 
 touch /var/log/trafficserver/diags.log
-tail -F /var/log/trafficserver/diags.log
+tail -Fn +1 /var/log/trafficserver/diags.log
diff --git a/infrastructure/cdn-in-a-box/mid/run.sh b/infrastructure/cdn-in-a-box/mid/run.sh
index 27cf2b6..b707bc9 100755
--- a/infrastructure/cdn-in-a-box/mid/run.sh
+++ b/infrastructure/cdn-in-a-box/mid/run.sh
@@ -57,19 +57,13 @@ done
 
 to-enroll mid $CDN || (while true; do echo "enroll failed."; sleep 3 ; done)
 
-function testenrolled() {
-	local tmp="$(to-get	'api/1.3/servers?name=mid')"
-	tmp=$(echo $tmp | jq '.response[]|select(.hostName=="mid")')
-	echo "$tmp"
-}
-
 while [[ -z "$(testenrolled)" ]]; do
 	echo "waiting on enrollment"
 	sleep 3
 done
 
 # Leaves the container hanging open in the event of a failure for debugging purposes
-/opt/ort/traffic_ops_ort.py BADASS ALL "https://$TO_FQDN:$TO_PORT" "$TO_ADMIN_USER:$TO_ADMIN_PASSWORD" || { echo "Failed"; }
+traffic_ops_ort -k BADASS ALL "https://$TO_FQDN:$TO_PORT" "$TO_ADMIN_USER:$TO_ADMIN_PASSWORD" || { echo "Failed"; }
 
 envsubst < "/etc/cron.d/traffic_ops_ort-cron-template" > "/etc/cron.d/traffic_ops_ort-cron" && rm -f "/etc/cron.d/traffic_ops_ort-cron-template"
 chmod "0644" "/etc/cron.d/traffic_ops_ort-cron" && crontab "/etc/cron.d/traffic_ops_ort-cron"
@@ -77,4 +71,4 @@ chmod "0644" "/etc/cron.d/traffic_ops_ort-cron" && crontab "/etc/cron.d/traffic_
 crond -im off
 
 touch /var/log/trafficserver/diags.log
-tail -F /var/log/trafficserver/diags.log
+tail -Fn +1 /var/log/trafficserver/diags.log
diff --git a/infrastructure/cdn-in-a-box/ort/setup.py b/infrastructure/cdn-in-a-box/ort/setup.py
index c76b6f4..3589889 100755
--- a/infrastructure/cdn-in-a-box/ort/setup.py
+++ b/infrastructure/cdn-in-a-box/ort/setup.py
@@ -16,15 +16,12 @@
 
 
 """
-The setuptools-based install script for connvitals-monitor
+The setuptools-based install script for Traffic Ops ORT
 """
 
 import os
 import sys
 
-# RPMs generated for fedora/rhel/centos need to have a different name
-# (debian/ubuntu automatically prepends python3-, but those do not)
-import platform
 from setuptools import setup, find_packages
 
 here = os.path.abspath(os.path.dirname(__file__))
@@ -66,7 +63,7 @@ setup(
 	keywords='network connection configuration TrafficControl',
 	packages=find_packages(exclude=['contrib', 'docs', 'tests']),
 	install_requires=['setuptools', 'typing', 'requests', 'urllib3', 'distro', 'psutil'],
-	data_files=[('etc/crontab', ['connmonitor.service'])],
+	# data_files=[('etc/crontab', ['traffic_ops_ort.crontab'])],
 	entry_points={
 		'console_scripts': [
 			'traffic_ops_ort=traffic_ops_ort:main',
diff --git a/infrastructure/cdn-in-a-box/cache/crontab b/infrastructure/cdn-in-a-box/ort/traffic_ops_ort.crontab
similarity index 93%
rename from infrastructure/cdn-in-a-box/cache/crontab
rename to infrastructure/cdn-in-a-box/ort/traffic_ops_ort.crontab
index e2690f5..ccb522c 100644
--- a/infrastructure/cdn-in-a-box/cache/crontab
+++ b/infrastructure/cdn-in-a-box/ort/traffic_ops_ort.crontab
@@ -14,4 +14,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-*/1 * * * * /opt/ort/traffic_ops_ort.py SYNCDS ALL https://$TO_FQDN $TO_ADMIN_USER:$TO_ADMIN_PASSWORD >> /var/log/ort.log 2>> /var/log/ort.log
+*/1 * * * * /usr/bin/traffic_ops_ort -k SYNCDS ALL https://$TO_FQDN $TO_ADMIN_USER:$TO_ADMIN_PASSWORD >> /var/log/ort.log 2>> /var/log/ort.log
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
index e6147d0..712ff5a 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
@@ -43,6 +43,8 @@ export CURLOPTS=${CURLOPTS:--LfsS}
 export CURLAUTH=${CURLAUTH:--k}
 export COOKIEJAR=$(mktemp)
 
+export MY_HOSTNAME="$(hostname -s)"
+
 login=$(mktemp)
 
 cleanup() {
@@ -109,7 +111,7 @@ to-post() {
 	fi
 	to-auth && \
 	    curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X POST $data "$TO_URL/$1"
-	[[ -n $t ]] && rm "$t"    
+	[[ -n $t ]] && rm "$t"
 }
 
 to-put() {
@@ -134,13 +136,13 @@ to-delete() {
 #         serverType - the type of the server to be created; one of "edge", "mid", "tm"
 to-enroll() {
 
-	while true; do 
+	while true; do
 		[ -d "$ENROLLER_DIR" ] && break
 		echo "Waiting for $ENROLLER_DIR ..."
 		sleep 2
 	done
 
-	while true; do 
+	while true; do
 		[ "$serverType" = "to" ] && break
 		[ -f "$ENROLLER_DIR/initial-load-done" ] && break
 		echo "Waiting for traffic-ops to do initial load ..."
@@ -159,7 +161,6 @@ to-enroll() {
 	fi
 
 	export MY_NET_INTERFACE='eth0'
-	export MY_HOSTNAME="$(hostname -s)"
 	export MY_DOMAINNAME="$(dnsdomainname)"
 	export MY_IP="$(ifconfig $MY_NET_INTERFACE | grep 'inet ' | tr -s ' ' | cut -d ' ' -f 3)"
 	export MY_GATEWAY="$(route -n | grep $MY_NET_INTERFACE | grep -E '^0\.0\.0\.0' | tr -s ' ' | cut -d ' ' -f2)"
@@ -198,7 +199,7 @@ to-enroll() {
 				export MY_CACHE_GROUP="CDN_in_a_Box_Edge"
 			fi
 			;;
-		"to" ) 
+		"to" )
 			export MY_TYPE="TRAFFIC_OPS"
 			export MY_PROFILE="TRAFFIC_OPS"
 			export MY_STATUS="ONLINE"
@@ -250,3 +251,10 @@ to-enroll() {
 
 	sleep 3
 }
+
+# Tests that this server exists in Traffic Ops
+function testenrolled() {
+	local tmp="$(to-get	'api/1.3/servers?name='$MY_HOSTNAME'')"
+	tmp=$(echo $tmp | jq '.response[]|select(.hostName=="'"$MY_HOSTNAME"'")')
+	echo "$tmp"
+}