Skip to content

Instantly share code, notes, and snippets.

@AlexAtkinson
Created September 12, 2024 14:11
Show Gist options
  • Save AlexAtkinson/524035a8e90b67ed2b8a0d9e493bbb83 to your computer and use it in GitHub Desktop.
Save AlexAtkinson/524035a8e90b67ed2b8a0d9e493bbb83 to your computer and use it in GitHub Desktop.
BASH from the PAST: Create a Mesos Master Instance
#!/bin/bash
# ----------------------------------------------------------------------
# /root/build_mesos-master.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
# ----------------------------------------------------------------------
# User Defined Variables
# ----------------------------------------------------------------------
read -p "Enter mesos-master ID: " id
read -p "Enter mesos cluster name: " cluster-name
# ----------------------------------------------------------------------
# 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 Mesosphere..."
apt-get -y install mesosphere ; if [ $? -eq 0 ] ; then echo -e "\e[00;32mSUCCESS\e[00m - mesosphere installed." ; else echo -e "\e[00;31mERROR\e[00m - mesosphere not installed." ; fi
echo "Building configuration files..."
echo $id > /etc/zookeeper/conf/myid ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/zookeeper/conf/myid not modified." ; fi
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 correctly." ; fi
sed -ri 's/^#?server.1=zookeeper1:2888:3888/server.1=$server1:2888:3888/' /etc/zookeeper/conf/zoo.cfg ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/zookeeper/conf/zoo.cfg not modified correctly." ; fi
sed -ri 's/^#?server.2=zookeeper2:2888:3888/server.2=$server2:2888:3888/' /etc/zookeeper/conf/zoo.cfg ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/zookeeper/conf/zoo.cfg not modified correctly." ; fi
sed -ri 's/^#?server.3=zookeeper3:2888:3888/server.3=$server3:2888:3888/' /etc/zookeeper/conf/zoo.cfg ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/zookeeper/conf/zoo.cfg not modified correctly." ; fi
echo 2 > /etc/mesos-master/quorum ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos-master/quorum not modified correctly." ; fi
echo $cluster-name > /etc/mesos-master/cluster ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos-master/cluster not modified correctly." ; fi
echo $ip > /etc/mesos-master/ip ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos-master/ip not modified correctly." ; fi
echo $ip > /etc/mesos-master/hostname ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/mesos-master/hostname not modified correctly." ; fi
mkdir -p /etc/marathon/conf ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/marathon/conf not created." ; fi
cp /etc/mesos-master/hostname /etc/marathon/conf ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/marathon/conf not created." ; fi
cp /etc/mesos/zk /etc/marathon/conf/master ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/marathon/conf/master not created." ; fi
cp /etc/marathon/conf/master /etc/marathon/conf/zk ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/marathon/conf/zk not created." ; fi
sed -i 's/mesos/marathon/' /etc/marathon/conf/zk ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - /etc/marathon/conf/zk not modified correctly." ; fi
echo "Finalizing Services..."
ps aux | grep mesos-slave | grep -v grep ; if [ $? -eq 1 ] ; then true ; else service mesos-slave stop ; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - mesos-slave was unable to shutdown successfully." ; fi
update-rc.d -f mesos-slave remove ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - mesos-slave not removed from startup services successfully." ; fi
ps aux | grep zookeeper | grep -v grep ; if [ $? -eq 0 ] ; then service zookeeper restart ; else service zookeeper start; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - zookeeper was unable to start successfully." ; fi
ps aux | grep mesos-master | grep -v grep ; if [ $? -eq 0 ] ; then service mesos-master restart ; else service mesos-master start; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - mesos-master was unable to start successfully." ; fi
ps aux | grep marathon | grep -v grep ; if [ $? -eq 0 ] ; then service marathon restart ; else service marathon start; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - marathon was unable to start successfully." ; fi
ps aux | grep chronos | grep -v grep ; if [ $? -eq 0 ] ; then service chronos restart ; else service chronos start; fi ; if [ $? -eq 0 ] ; then true ; else echo -e "\e[00;31mERROR\e[00m - chronos was unable to start successfully." ; fi
@AlexAtkinson
Copy link
Author

AlexAtkinson commented Sep 12, 2024

Didn't bother with AMIs at the time. Ansible was still gaining adoption...
The earliest example of my resultcheck function... Ah memories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment