Create a gist now

Instantly share code, notes, and snippets.

@massenz /README.rst
Last active May 23, 2017

What would you like to do?
Apache Mesos build and install scripts; optionally runs the Master/Slave locally and executes a demo (C++) framework against it, to validate it all went according to plan

Apache Mesos Build scripts

The Getting started instructions are a good start (no surprise there!) but are somewhat incomplete and currently look a bit outdated (I plan to fix them soon): however, the outcome has been that I have struggled more than I felt necessary in building and running Mesos on a dev VM (Ubuntu 14.04 running under VirtualBox).

Some of the issue seem to arise from the unfortunate combination of Mesos Master trying to guess its own IP address, the VM being (obviously) non-DNS resolvable and, eventually, the Slave and the Framework failing to properly communicate with the Master.

In the process of solving this, I ended up automating all the dependencies installation, building and running the framework; I have then broken it down into the following modules to make it easier to run only parts of the process.


There are two ways of obtaining an Apache Mesos distribution: either via a tarball, or cloning the repo; either are supported, but will require running the scripts differently: they should all be copied inside the same directory (eg /home/user/scripts) and run from there.

Obviously, make them executable via chmod a+x /home/user/scripts/{build,install,run}

This has been tested both on a VM and a physical box, both running Ubuntu 14.04.


If you want to download and install from the tarball, execute:


optionally followed by the version number (eg, 0.23.0): it currently defaults to 0.22.0.

If you have already cloned the git repo, just run:


optionally followed by:


NOTE As these scripts need to cd in the correct directories, due to the expansion of dirname $0, this will fail unless it's run with an absolute path (as shown above) or using shell expansion wildcards (eg ~).

Running it like ``./my_scripts/`` will most likely fail.

# Builds the Apache Mesos distribution
# Created: M. Massenzio, 2015-04-02
source `dirname $0`/
# Ensure apt-get is up to date.
sudo apt-get update && sudo apt-get -y upgrade
# Install build tools.
msg "Installing necessary dependencies, go grab a book: this WILL take time"
sudo apt-get -y install build-essential python-dev python-boto \
libcurl4-nss-dev libsasl2-dev \
maven libapr1-dev libsvn-dev
# Install OpenJDK java, only if needed
JAVAC=$(which javac)
if [[ -z $JAVAC ]]; then
msg "Installing Open JDK 7"
sudo apt-get install -y openjdk-7-jdk
# Check that we are in the right directory
if [[ ! -e bootstrap ]]; then
error "This does not appear to be Mesos's top-level directory"
error "This is the current directory: `pwd`"
exit 1
# Only needed for building from git cloned repo
if [[ -d .git ]]; then
# Install autotoconf, automake and libtool
sudo apt-get install -y autoconf libtool
msg "Running the bootstrap script"
wrap ./bootstrap
# Configure and build.
msg "Building Mesos, this will take a long time..."
# TODO: should we run make clean first?
mkdir build
cd build
wrap ../configure
wrap make
# Run test suite.
msg "Testing build"
wrap make check
# Install (***Optional***).
msg "All tests passed; now installing to your system..."
wrap sudo make install
mesos_lib=$(echo $LD_LIBRARY_PATH | grep /usr/local/lib)
if [[ -z $mesos_lib ]]; then
msg "Adding /usr/local/lib to LD_LIBRARY_PATH to .bashrc"
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib" >> ~/.bashrc
msg "Mesos install successful" "SUCCESS"
# Common utility functions
# Created: M. Massenzio, 2015-04-02
# Emits a string to console (poor man's log)
# with an optional log level (can be anything, will be prepended to the message)
# usage: msg 'msg' [level]
function msg {
local level=${2:-"INFO"}
echo "[$level] $1"
# Emits an Error message
# usage: error "Something went wrong"
function error {
msg $1 "ERROR"
# Wraps a command and exits if it fails
# usage: wrap cat /tmp/foo/bar
function wrap {
local CMD="$@"
if [[ $? != 0 ]]; then
error "Failed: $CMD"
exit 1
# Created: M. Massenzio, 2015-04-02
source `dirname $0`/
declare -r VERSION=${1:-"0.22.0"}
# Get Mesos - update the $VERSION if you need a more recent release
declare -r dir="${HOME}/mesos-dev"
msg "Getting Mesos $VERSION and unpacking to $dir"
mkdir -p $dir
cd $dir
msg "Downloading Apache Mesos ($VERSION)"
if [[ ! -e "mesos-$VERSION.tar.gz" ]]; then
error "Failed to download Mesos distribution: mesos-$VERSION.tar.gz"
exit 1
tar -zxf mesos-$VERSION.tar.gz
# Change working directory (the actual name will depend on Mesos version no.)
cd $dir/mesos-$VERSION
# Running the build script
msg "Running the Build script"
wrap `dirname $0`/
read -p "Do you want to run a test framework (y/n)? " choice
if [[ $choice == 'y' ]]; then
`dirname $0`/
# Runs Apache Mesos Master/Slave and (optionally) a demo/test framework
# Created: M. Massenzio, 2015-04-02
source `dirname $0`/
msg "Running Apache Mesos Master, Slave and Demo Framework (C++)"
if [[ ! -e "./build/bin/" ]]; then
error "Could not find the script, are you in the top-level mesos repository?"
exit 1
cd build
# Creating the logging directory and the work directory
declare -r LOGS="/var/log/mesos"
declare -r WORKDIR="/var/lib/mesos"
for dir in $LOGS $WORKDIR ; do
if [[ ! -d "$dir" ]]; then
sudo mkdir -p $dir
sudo chmod 2775 $dir
sudo chown $USER:users $dir
# Clean up from previous sessions (will make the slave fail if there was a config change)
rm -f /tmp/mesos/meta/slaves/latest
msg "Starting the Master / Slave, logs in $LOGS, work dir $WORKDIR"
./bin/ --ip= --work_dir=$WORKDIR \
--log_dir=$LOGS >$LOGS/master.logs 2>&1 &
if [[ $? != 0 ]]; then
error "Failed starting the Master"
exit 1
echo "$master_pid" >/tmp/MESOS_MASTER_PID
# Cleaning up in case of previous failed runs
rm -rf /tmp/mesos/slaves/
# Note the use of `hostname` here and below, instead of just 'localhost'; this is due to the fact
# that the Master tries to auto-resolve its hostname and (where DNS resolution is not enabled and
# it relies instead on /etc/hosts) this will cause mismatched servername between slave/master/framework
# (This seems particularly bad in Ubuntu, where the hostname is mapped in /etc/hosts to
./bin/ --master=`hostname`:5050 > $LOGS/slave.logs 2>&1 &
if [[ $? != 0 ]]; then
error "Failed starting the Slave"
exit 1
echo "$slave_pid" >/tmp/MESOS_SLAVE_PID
msg "Master / Slave running in background in this session"
msg "Master PID: $master_pid"
msg "Slave PID: $slave_pid"
msg "To terminate use : kill \`cat /tmp/MESOS_MASTER_PID\` && kill \`cat /tmp/MESOS_SLAVE_PID\`"
msg "Starting the test framework - check progress in the Web UI at http://localhost:5050"
msg "This should complete reasonably quickly, if it just hangs around, probably the slave exited"
msg "Check the slave logs in $LOGS/slave.logs (terminate this script with Ctrl-C)"
# TODO: we could actually start this in background, grab the PID, sleep for a while, then kill it
# if it hasn't terminated yet (overkill?)
./src/test-framework --master=`hostname`:5050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment