rmatharu commented on a change in pull request #62: Adding support for lxc on
yarn for Samza
URL: https://github.com/apache/samza-hello-samza/pull/62#discussion_r295119154
##
File path: bin/setup-lxc
##
@@ -0,0 +1,345 @@
+#!/bin/bash -e
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This script will download, setup, start, and stop servers for Kafka, YARN,
and ZooKeeper,
+# as well as downloading, building and locally publishing Samza
+
+
+COMMAND=$1
+ARG0=$2
+ARG1=$3
+
+SHARED_LXC_DIR=/lxc-shared
+POSSIBLE_LXC_INTERFACES=( virbr0 lxcbr0)
+YARN_SITE_XML=conf/yarn-site.xml
+NM_LIVENESS_MS=1 #value of the yarn.nm.liveness-monitor.expiry-interval-ms
variable
+LXC_INSTANCE_TYPE="fedora"
+LXC_ROOTFS_DIR=/var/lib/lxc
+LXC_INSTANCE_START_NM_SCRIPT=startNodeManager
+
+RESOLV_CONF_FILE=/etc/resolv.conf
+
+# Helper function to test an IP address for validity:
+# Usage:
+# valid_ip IP_ADDRESS
+# if [[ $? -eq 0 ]]; then echo good; else echo bad; fi
+# OR
+# if valid_ip IP_ADDRESS; then echo good; else echo bad; fi
+#
+function valid_ip()
+{
+local ip=$1
+local stat=1
+
+if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
+OIFS=$IFS
+IFS='.'
+ip=($ip)
+IFS=$OIFS
+[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
+&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
+stat=$?
+fi
+return $stat
+}
+
+function check_OS()
+{
+ #Check if OS is linux
+ if [[ "$OSTYPE" == "linux-gnu" ]]; then
+ echo "OS check passed."
+ else
+ echo "Only RHEL-Linux is currently supported for this setup.
Exiting ..."
+ exit 0
+ fi
+}
+
+
+function lxc_setup()
+{
+
+ #Install LXC (and its dependencies)
+ echo "Beginning installation. Installing lxc on your machine"
+ sudo yum -y install epel-release
+ sudo yum -y install lxc lxc-templates libcap-devel libcgroup wget
bridge-utils lxc-extra --skip-broken
+ echo "LXC installation complete."
+
+
+ lxcInterface=""
+ gatewayIP=""
+
+for interface in ${POSSIBLE_LXC_INTERFACES[@]}
+do
+echo "Checking if $interface is valid"
+ip_address=`ip addr show $interface | grep "inet\b" | awk
'{print $2}' | cut -d/ -f1`
+
+if valid_ip $ip_address; then
+echo "Interface $interface is valid for using with LXC
instances."
+lxcInterface=$interface
+gatewayIP=$ip_address
+break;
+else
+echo "Interface $interface does not appear to be
valid."
+continue;
+fi
+done
+
+ if [[ -z "$lxcInterface" ]]; then
+ echo "Did not find a valid network interface for use with LXC.
Install LXC manually (https://linuxcontainers.org/lxc/getting-started/) and
re-run."
+ exit 0
+ fi
+
+ #Print the valid interface found
+ echo "Using interface "$lxcInterface "($gatewayIP) for use with LXC"
+
+ # Create shared directory for sharing between base machine and
LXC-instances
+ echo "Creating dir $SHARED_LXC_DIR to be shared between base machine
and LXC-instances"
+ sudo mkdir -p $SHARED_LXC_DIR && sudo chmod 777 $SHARED_LXC_DIR
+
+ # Setting gateway IP address in conf/yarn-site.xml
+ echo "Setting yarn.resourcemanager.hostname="$gatewayIP in
$YARN_SITE_XML
+ sed -i
"/yarn.resourcemanager.hostname<\/name>/!b;n;c$gatewayIP"
$YARN_SITE_XML
+
+ # Adding RM bind host in conf/yarn-site.xml
+ echo "Setting yarn.resourcemanager.bind-host=0.0.0.0" in $YARN_SITE_XML
+ if [[ ! -z $(grep "yarn.resourcemanager.bind-host" conf/yarn-site.xml)
]]; then
+
+ # Setting yarn.resourcemanager.bind-host to 0.0.0.0
+ sed -i
"/yarn.resourcemanager.bind-host<\/name>/!b;n;c0.0.0.0"
$YARN_SITE_XML
+ else
+
+ # Appending RM bind host in conf/yarn-site.xml
+ sed -i