Skip to content

Instantly share code, notes, and snippets.

@antonlindstrom
Created January 31, 2014 16:34
Show Gist options
  • Save antonlindstrom/8735710 to your computer and use it in GitHub Desktop.
Save antonlindstrom/8735710 to your computer and use it in GitHub Desktop.
Marathon upstart script & wrapper
#HOST=127.0.0.1
MASTER=`cat /etc/mesos/zk`
#!/bin/bash
set -o errexit -o nounset -o pipefail
function marathon {
local etc_marathon=/etc/marathon
local args=()
[[ ! -f /etc/default/marathon ]] || . /etc/default/marathon
[[ ! ${MASTER:-} ]] || args+=( --master "$MASTER" )
[[ ! ${HOST:-} ]] || args+=( -h "$HOST" )
for f in "$etc_marathon"/* # cluster log_dir port &al.
do
if [[ -f $f ]]
then
local name="$(basename "$f")"
if [[ $name == '?'* ]] # Recognize flags (options without values)
then args+=( --"$name" )
else args+=( --"$name"="$(cat "$f")" )
fi
fi
done
logged /usr/local/marathon/bin/start "${args[@]}"
}
# Send all output to syslog and tag with PID and executable basename.
function logged {
local tag="${1##*/}[$$]"
exec 1> >(exec logger -p user.info -t "$tag")
exec 2> >(exec logger -p user.err -t "$tag")
exec "$@"
}
function msg { out "$*" >&2 ;}
function err { local x=$? ; msg "$*" ; return $(( $x == 0 ? 1 : $x )) ;}
function out { printf '%s\n' "$*" ;}
marathon "$@"
description "Marathon scheduler for Mesos"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
exec /usr/bin/marathon-init-wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment