Skip to content

Instantly share code, notes, and snippets.

@AlexAtkinson
Created September 12, 2024 14:13
Show Gist options
  • Save AlexAtkinson/44cc8b31a806138656fb7da2ad92817e to your computer and use it in GitHub Desktop.
Save AlexAtkinson/44cc8b31a806138656fb7da2ad92817e to your computer and use it in GitHub Desktop.
BASH from the PAST: Create a Mesos Agent Instance
#!/bin/bash
# ----------------------------------------------------------------------
# /root/build_mesos-slave.sh
# mesos-master auto-build
#
# ----------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------
user="root"
dir="/root"
distro=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
codename=$(lsb_release -cs)
ip=$(ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')
server1="192.168.1.x"
server2="192.168.1.y"
server3="192.168.1.z"
# ----------------------------------------------------------------------
# Sanity Checks
# ----------------------------------------------------------------------
if [ "$(whoami)" != $user ] ; then
echo -e "\nError: This script *must* be run as $user!\n"
exit 1
fi
if [ "$(pwd)" != $dir ] ; then
echo -e "\nError: This script *must* be located in $dir!\n"
exit 1
fi
# ----------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------
function resultcheck {
if [ $? -eq $1 ] ; then echo -e "$TASK: \e[00;32mSUCCESS\e[00m" | tee -a build.log ; else echo -e "$TASK: \e[00;31mERROR\e[00m" | tee -a build.log ; fi
}
# ----------------------------------------------------------------------
# Main Operations
# ----------------------------------------------------------------------
echo "Adding repositories..."
apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF ; if [ $? -eq 0 ] ; then echo -e "\e[00;32mSUCCESS\e[00m - apt key received." ; else echo -e "\e[00;31mERROR\e[00m - apt key NOT received." ; fi
echo "deb http://repos.mesosphere.io/${distro} ${codename} main" | tee /etc/apt/sources.list.d/mesosphere.list ; if [ $? -eq 0 ] ; then echo -e "\e[00;32mSUCCESS\e[00m - mesosphere repository added." ; else echo -e "\e[00;31mERROR\e[00m - mesosphere repository NOT added." ; fi
echo "Re-synchronize the package index files from their sources..."
apt-get -y update ; if [ $? -eq 0 ] ; then echo -e "\e[00;32mSUCCESS\e[00m - package index files synchronized." ; else echo -e "\e[00;31mERROR\e[00m - package index files NOT synchronized." ; fi
echo "Installing Mesos..."
apt-get -y install mesos ; if [ $? -eq 0 ] ; then echo -e "\e[00;32mSUCCESS\e[00m - mesos installed." ; else echo -e "\e[00;31mERROR\e[00m - mesos NOT installed." ; fi
echo "Building configuration files..."
echo "zk://$server1:2181,$server2:2181,$server3:2181/mesos" > /etc/mesos/zk ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos/zk NOT modified." ; fi
echo $ip > /etc/mesos-slave/ip ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos-slave/ip NOT modified." ; fi
echo $ip > /etc/mesos-slave/hostname ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos-slave/hostname NOT modified." ; fi
echo "Finalizing Services..."
ps aux | grep zookeeper | grep -v grep ; if [ $? -eq 1 ] ; then true ; else service zookeeper stop ; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - zookeeper NOT shutdown...?" ; fi
update-rc.d -f zookeeper remove ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - zookeeper NOT removed from startup services." ; fi
ps aux | grep mesos-master | grep -v grep ; if [ $? -eq 1 ] ; then true ; else service mesos-master stop ; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - mesos-master NOT shutdown...?" ; fi
update-rc.d -f mesos-master remove ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - mesos-master not removed from startup services." ; fi
sleep 5
ps aux | grep mesos-slave | grep -v grep ; if [ $? -eq 0 ] ; then service mesos-slave restart ; else service mesos-slave start; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - mesos-slave was unable to start successfully." ; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment