#!/bin/bash #set -x IMAGE="maprtech/edf-seed-container:latest" INTERFACE="en0" RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color usage() { echo "This script will deploy HPE DataFabric on seed node." echo echo "Syntax: ./datafabric_container_setup.sh [-i|--image] [-p|--publicipv4dns] [-f|--proxyfiledetails]" echo "options:" echo "-i|--image this is optional,By default it will pull image having latest tag, we can also provide image which has custom tag example:maprtech/edf-seed-container:7.4.0_9.1.2" echo "-p|--publicipv4dns is the public IPv4 DNS and needed for cloud deployed seed nodes. Note that both inbound and outbound trafic on port 8443 needs to be enabled on the cloud instance. Otherwise, the Data Fabric UI cannot be accessible" echo "-f|--proxyfiledetails is the location of file from where proxy details provided by user are copied to docker container." echo } os_name=$(. /etc/os-release 2> /dev/null && echo "$ID") &> /dev/null os_vers=`uname -s` > /dev/null 2>&1 install_docker_linux() { echo "Docker is not present on the system. Installing it.." echo "Docker installation may take 6 to 8 minutes..." echo "There is no input/intervention required from user side" if [ $os_name == "ubuntu" ]; then sudo apt-get update > /dev/null sudo apt-get -y install ca-certificates curl gnupg > /dev/null sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - > /dev/null 2>&1 sudo chmod a+r /etc/apt/keyrings/docker.gpg echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg trusted=yes] https://download.docker.com/linux/ubuntu \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update > /dev/null 2>&1 sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin > /dev/null 2>&1 systemctl daemon-reload > /dev/null 2>&1 systemctl restart docker > /dev/null 2>&1 systemctl enable docker > /dev/null 2>&1 elif [ $os_name == "rhel" ]; then dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo > /dev/null dnf install docker-ce --nobest -y > /dev/null elif [ $os_name == "centos" ]; then sudo yum install -y yum-utils > /dev/null sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo > /dev/null sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin fi sleep 120 systemctl start docker > /dev/null 2>&1 #check if docker is installed and running docker info > /dev/null 2>&1 if [ $? != 0 ] ; then echo echo "Docker installation on the node where this script is ran is not successfull. Please install docker manually to proceed forward" exit else echo echo "Docker installation on node from script was successfull" fi } set_noproxy() { if [ -z "${os_vers}" ] || [ -z "${hostName}" ] || [ -z "${shortHostName}" ] || \ [ -z ${container_engine} ] || [ -z ${CID} ];then echo -e "Few uninitialized variables, skipping setting no_proxy" return fi if [ "$os_vers" == "Darwin" ]; then $container_engine exec $CID bash -c "sed -i '' 's/^\s*#\?.*\(no_proxy\)\s*=\s*\(.*\)/\1=\2,'\"${hostName},${shortHostName}\"'/I' /etc/environment /etc/profile.d/proxy.sh" > /dev/null 2>&1 elif [ "$os_vers" == "Linux" ]; then $container_engine exec $CID bash -c "sed -i 's/^\s*#\?.*\(no_proxy\)\s*=\s*\(.*\)/\1=\2,'\"${hostName},${shortHostName}\"'/I' /etc/environment /etc/profile.d/proxy.sh" > /dev/null 2>&1 else echo -e "Unsupported host OS : ${os_vers}, only support Darwin/Linux" fi $container_engine exec $CID bash -c "grep -q -i 'no_proxy' /etc/environment || echo \"export no_proxy=${hostName},${shortHostName}\" >> /etc/environment" >/dev/null 2>&1 $container_engine exec $CID bash -c "grep -q -i 'no_proxy' /etc/profile.d/proxy.sh || echo \"export no_proxy=${hostName},${shortHostName}\" >> /etc/profile.d/proxy.sh" >/dev/null 2>&1 } #checking if required memory is present or not memory_requirement=1 if [ "$os_vers" == "Darwin" ]; then memory_available_mac=$(system_profiler SPHardwareDataType | grep "Memory" | awk '{print $2}') &>/dev/null if [ $memory_available_mac -lt 8 ] ; then echo -e "${GREEN}RAM NEEDED \t :\t 8 GB" echo -e "${RED}RAM AVILABLE \t :\t $memory_available_mac GB" echo -e "${RED}Please try to spin up seed node on client having sufficient memory${NC}" memory_requirement=0 exit fi fi if [ "$os_vers" == "Linux" ]; then memory_available_linux=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}') &>/dev/null if [ $memory_available_linux -lt 8000000 ]; then echo -e "${GREEN}RAM NEEDED \t :\t 8 GB" echo -e "${RED}RAM AVAILABLE \t :\t $memory_available_linux" echo -e "${RED}Please try to spin up seed node on client having sufficient memory${NC}" memory_requirement=0 exit fi fi #setting default value of container_engine to docker. Here container_engine refers to the container runtime installed. container_engine='docker' # Check if Docker is installed docker info > /dev/null 2>&1 DOCKER_STATUS=$? # Check if Podman is installed podman info > /dev/null 2>&1 PODMAN_STATUS=$? # If Podman is installed, set container_engine=podman if [ $PODMAN_STATUS = 0 ]; then container_engine='podman' IMAGE="docker.io/maprtech/edf-seed-container:latest" fi # If docker is installed, set container_engine=docker if [ $DOCKER_STATUS = 0 ]; then container_engine='docker' fi # If neither Docker nor Podman is available, install docker. if [ $DOCKER_STATUS != 0 ] && [ $PODMAN_STATUS != 0 ]; then if [ "$os_vers" == "Darwin" ];then echo -e "${RED}Docker is not installed/not-running on the MacBook where this script is ran.Please install/start docker to proceed forward" echo -e "${GREEN}Reference link to install : https://docs.docker.com/desktop/install/mac-install/${NC}" exit elif [ "$os_vers" == "Linux" ]; then install_docker_linux fi fi #check connectivity to docker hub container_engine_running=1 $container_engine run hello-world > /dev/null 2>&1 if [ $? != 0 ]; then echo -e "${RED}$container_engine is not running on the system" echo -e "${RED}$container_engine is installed/running on the system but we are not able to pull images from docker" echo -e "${RED}Please check internet connectivity or if the machine is behind a proxy and take appropriate action accordingly${NC}" container_engine_running=0 exit fi #remove the hello-world image we ran in earlier step CID_Hello=$($container_engine ps -a | grep hello-world | awk '{ print $1 }' | tail -1 ) if [ -n "$CID_Hello" ]; then $container_engine stop $CID_Hello > /dev/null 2>&1 $container_engine rm -f $CID_Hello > /dev/null 2>&1 fi #check if ports used by datafabric is already used by some other process port_available=1 $container_engine ps -q > /dev/null 2>&1 if [ $? == 0 ]; then # Define the ports you want to check ports=(7221 5660 5692 5724 5756 8443 9443 8188 8080 7222 5181) # Loop through each port and check if it's in use for port in "${ports[@]}"; do # Check if port is in use by any container, and exclude containers with "edf-seed-container" in the image name if [[ "$os_vers" == "Darwin" ]]; then # macOS: use lsof port_in_use=$(lsof -nP -iTCP -sTCP:LISTEN | grep ":$port" | awk '{print $2}' | head -n 1) else # Linux: use ss port_in_use=$(ss -tulnp | grep ":$port " | awk '{print $6}' | cut -d',' -f2) fi if [[ -n "$port_in_use" ]]; then # Get the container ID using that port container_using_port=$($container_engine ps -q --filter "publish=$port") # Check if the container is excluded (based on image name containing "edf-seed-container") container_image=$($container_engine ps -a --filter "id=$container_using_port" --format "{{.Image}}") if [[ "$container_image" == *"edf-seed-container"* ]]; then port_available=1 else echo "Please check port availability as Port $port is in use by container $container_using_port with image '$container_image'." port_available=0 exit 1 fi else port_available=1 fi done fi if [ $memory_requirement -eq 1 ] && [ $container_engine_running -eq 1 ] && [ $port_available -eq 1 ]; then echo -e "\t\t${GREEN}RAM NEEDED \t :\t AVAILABLE" echo -e "\t\t${GREEN}$container_engine STATUS \t :\t RUNNING" echo -e "\t\t${GREEN}PORTS NEEDED \t :\t AVAILABLE" echo -e "\t\tPROCEEDING FORWARD WITH DEPLOYING SEED NODE${NC}" fi while [ $# -gt 0 ] do case "$1" in -i|--image) shift; IMAGE=$1;; -p|--publicipv4dns) shift; PUBLICIPV4DNS=$1;; -f|--proxyfiledetails) shift; PROXYFILEDETAILS=$1;; *) shift; usage exit;; esac shift done which ipconfig &>/dev/null if [ $? -eq 0 ]; then INTERFACE=$(route -n get default | grep interface | awk '{print $2}') IP=$(ipconfig getifaddr $INTERFACE) else INTERFACE=$(ip route | grep default | awk '{print $5}') IP=$(ip addr show $INTERFACE | grep -w inet | awk '{ print $2}' | cut -d "/" -f1) fi hostName="${hostName:-"edf-installer.hpe.com"}" clusterName=$(echo ${hostName} | cut -d '.' -f 1) shortHostName=$(echo $hostName | awk -F '.' '{print $1}') runMaprImage() { echo "Please enter the local sudo password for $(whoami)" sudo rm -rf /tmp/maprdemo sudo mkdir -p /tmp/maprdemo/hive /tmp/maprdemo/zkdata /tmp/maprdemo/pid /tmp/maprdemo/logs /tmp/maprdemo/nfs sudo chmod -R 777 /tmp/maprdemo/hive /tmp/maprdemo/zkdata /tmp/maprdemo/pid /tmp/maprdemo/logs /tmp/maprdemo/nfs PORTS=' -p 2222:22 -p 7221:7221 -p 5660:5660 -p 8443:8443 -p 8080:8080 -p 8188:8188 -p 7222:7222 -p 5181:5181 -p 5692:5692 -p 5724:5724 -p 5756:5756 -p 9443:9443' #export MAPR_EXTERNAL="0.0.0.0" #incase non-mac ipconfig command would not be found which ipconfig &>/dev/null if [ $? -eq 0 ]; then export MAPR_EXTERNAL=$(ipconfig getifaddr $INTERFACE) else export MAPR_EXTERNAL=$(ip addr show $INTERFACE | grep -w inet | awk '{ print $2}' | cut -d "/" -f1) fi if [ "${PUBLICIPV4DNS}" == "" ]; then echo "" else export PUBLICIPV4DNS="${PUBLICIPV4DNS}" fi $container_engine pull ${IMAGE} if [ $? != 0 ]; then echo "Failed to pull the image" exit 1 else $container_engine ps -a | grep edf-seed-container > /dev/null 2>&1 if [ $? == 0 ]; then running_CID=$($container_engine ps -a | grep edf-seed-container | awk '{ print $1 }' ) $container_engine stop $running_CID > /dev/null 2>&1 $container_engine rm $running_CID > /dev/null 2>&1 sleep 3 $container_engine run -d --privileged -v /tmp/maprdemo/zkdata:/opt/mapr/zkdata -v /tmp/maprdemo/pid:/opt/mapr/pid -v /tmp/maprdemo/logs:/opt/mapr/logs -v /tmp/maprdemo/nfs:/mapr $PORTS -e MAPR_EXTERNAL -e clusterName -e isSecure --hostname ${clusterName} ${IMAGE} > /dev/null 2>&1 else $container_engine stop $container_using_port > /dev/null 2>&1 $container_engine rm $container_using_port > /dev/null 2>&1 sleep 3 $container_engine run -d --privileged -v /tmp/maprdemo/zkdata:/opt/mapr/zkdata -v /tmp/maprdemo/pid:/opt/mapr/pid -v /tmp/maprdemo/logs:/opt/mapr/logs -v /tmp/maprdemo/nfs:/mapr $PORTS -e MAPR_EXTERNAL -e clusterName -e isSecure --hostname ${clusterName} ${IMAGE} > /dev/null 2>&1 fi fi # Check if container is started wihtout any issue sleep 5 # wait for container to start CID=$($container_engine ps -a | grep edf-seed-container | awk '{ print $1 }' ) RUNNING=$($container_engine inspect --format="{{.State.Running}}" $CID 2> /dev/null) ERROR=$($container_engine inspect --format="{{.State.Error}}" $CID 2> /dev/null) if [ "$RUNNING" == "true" -a "$ERROR" == "" ] then echo "Developer Sandbox Container $CID is running.." else echo "Failed to start Developer Sandbox Container $CID. Error: $ERROR" exit fi } if [ "$RUNNING" == "true" ] then # Container is running. # Change the IP in /etc/hosts and reconfigure client for the IP Change # Change the server side settings and restart warden grep ${hostName} /etc/hosts | grep ${IP} > /dev/null 2>&1 if [ $? -ne 0 ] then echo "Please enter the local sudo password for $(whoami)" sudo sed -i '/'${hostName}'/d' /etc/hosts &>/dev/null sudo sh -c "echo \"${IP} ${hostName} ${clusterName}\" >> /etc/hosts" sudo sed -i '' '/'${hostName}'/d' /opt/mapr/conf/mapr-clusters.conf &>/dev/null sudo /opt/mapr/server/configure.sh -C ${hostName} -N ${clusterName} > /dev/null 2>&1 # Change the external IP in the container echo "Please enter the root password of the container 'mapr' " ssh root@localhost -p 2222 " sed -i \"s/MAPR_EXTERNAL=.*/MAPR_EXTERNAL=${IP}/\" /opt/mapr/conf/env.sh " echo "Please enter the root password of the container 'mapr' " ssh root@localhost -p 2222 "service mapr-warden restart" fi fi runMaprImage sudo sed -i '/'${hostName}'/d' /etc/hosts &>/dev/null os_vers=`uname -s` > /dev/null 2>&1 `$container_engine cp $CID:/etc/environment /tmp/proxyseednode` `echo "export SEED_NODE=true" >> /tmp/proxyseednode` > /dev/null 2>&1 if [ "$os_vers" == "Darwin" ]; then if [ "${PROXYFILEDETAILS}" != "" ]; then `cat $PROXYFILEDETAILS >>/tmp/proxyseednode` > /dev/null 2>&1 fi fi if [ "$os_vers" == "Linux" ] && [ "${PROXYFILEDETAILS}" != "" ]; then `cat $PROXYFILEDETAILS >>/tmp/proxyseednode` > /dev/null 2>&1 fi if [ "$os_vers" == "Linux" ] && [ "${PROXYFILEDETAILS}" == "" ]; then `cat /etc/environment >>/tmp/proxyseednode` > /dev/null 2>&1 `cat /etc/profile.d/proxy.sh >>/tmp/proxyseednode` > /dev/null 2>&1 fi `$container_engine cp /tmp/proxyseednode $CID:/etc/environment` > /dev/null 2>&1 `rm -rf /tmp/proxyseednode` > /dev/null 2>&1 set_noproxy services_up=0 sleep_total=600 sleep_counter=0 if [ "$os_vers" == "Darwin" ]; then while [[ $sleep_counter -le $sleep_total ]] do curl -k -X GET "https://edf-installer.hpe.com:8443/rest/node/list?columns=svc" -u mapr:mapr123 &>/dev/null if [ $? -ne 0 ];then echo "services required for HPE Data fabric are coming up" sleep 60; sleep_counter=$((sleep_counter+60)) else services_up=1 break fi done fi if [ "$os_vers" == "Linux" ]; then while [[ $sleep_counter -le $sleep_total ]] do curl -k -X GET https://`hostname -f`:8443/rest/node/list?columns=svc -u mapr:mapr123 &>/dev/null if [ $? -ne 0 ];then echo "services required for HPE Data fabric are coming up" sleep 60; sleep_counter=$((sleep_counter+60)) else services_up=1 break fi done fi if [ $services_up -eq 1 ]; then echo echo "Client has been configured with the $container_engine container." echo if [ "${PUBLICIPV4DNS}" == "" ]; then echo "Please click on the link https://"${MAPR_EXTERNAL}":8443/app/df-installer/ to deploy data fabric" echo "For user documentation, see https://docs.ezmeral.hpe.com/datafabric/home/installation/installation_main.html" echo else echo "Please click on the link https://"${PUBLICIPV4DNS}":8443/app/df-installer/ to deploy data fabric" echo "For user documentation, see https://docs.ezmeral.hpe.com/datafabric/home/installation/installation_main.html" fi else echo echo "services didnt come up in stipulated 10 mins time" echo "please login to the container using ssh root@localhost -p 2222 with mapr as password and check further" echo "For documentation on steps to debug, see https://docs.ezmeral.hpe.com/datafabric/home/installation/troubleshooting_seed_node_installation.html" echo "once all services are up fabric UI is available at https://"${MAPR_EXTERNAL}":8443/app/df-installer/ and fabrics can be deployed from that page" echo fi