Skip to content

Instantly share code, notes, and snippets.

@jalaziz
Last active August 29, 2015 13:58
Show Gist options
  • Save jalaziz/10075303 to your computer and use it in GitHub Desktop.
Save jalaziz/10075303 to your computer and use it in GitHub Desktop.
Chronos Upstart
description "chronos"
# Start just after the System-V jobs (rc) to ensure networking and zookeeper
# are started. This is as simple as possible to ensure compatibility with
# Ubuntu, Debian, CentOS, and RHEL distros. See:
# http://upstart.ubuntu.com/cookbook/#standard-idioms
start on stopped rc RUNLEVEL=[2345]
respawn
script
export JAVA_LIBRARY_PATH="/usr/local/lib:/lib:/usr/lib"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-/lib}"
export LD_LIBRARY_PATH="$JAVA_LIBRARY_PATH:$LD_LIBRARY_PATH"
CHRONOS_HOME=/usr/local/lib/chronos
HEAP=384m
#If we're on Amazon, let's use the public hostname so redirect works as expected.
if public_hostname="$( curl -sSf --connect-timeout 1 http://169.254.169.254/latest/meta-data/public-hostname )"
then
HOSTNAME=$public_hostname
else
HOSTNAME=`hostname -f`
fi
#If /etc/mesos/zk exists, use it to configure zookeeper
if [ -f /etc/mesos/zk ]
then
MASTER=`cat /etc/mesos/zk`
ZK_HOSTS=`echo $MASTER | sed 's/zk:\/\///g;s/\/.*//'`
fi
# Override defaults with user-specificed defaults
[ ! -f /etc/default/chronos ] || . /etc/default/chronos
CHRONOS_JAR=${CHRONOS_JAR:-`echo $CHRONOS_HOME/chronos*.jar`}
VM_OPTS=${VM_OPTS:--Xmx"$HEAP" -Xms"$HEAP"}
# Redirect stdout to syslog
mkfifo /tmp/chronos-log-stdout-fifo
( logger -p user.info -t chronos </tmp/chronos-log-stdout-fifo & )
exec 1>/tmp/chronos-log-stdout-fifo
rm /tmp/chronos-log-stdout-fifo
# Redirect stderr to syslog
mkfifo /tmp/chronos-log-stderr-fifo
( logger -p user.err -t chronos </tmp/chronos-log-stderr-fifo & )
exec 2>/tmp/chronos-log-stderr-fifo
rm /tmp/chronos-log-stderr-fifo
exec java \
${VM_OPTS:+$VM_OPTS} \
${LIB_PATH:+-Djava.library.path=$LIB_PATH} \
${CHRONOS_JAR:+-cp $CHRONOS_JAR org.apache.mesos.chronos.scheduler.Main} \
${ZK_HOSTS:+--zk_hosts "$ZK_HOSTS"} \
${MASTER:+--master $MASTER} \
${HOSTNAME:+--hostname $HOSTNAME} \
${HTTP_PORT:+--http_port $HTTP_PORT} \
${HTTPS_PORT:+--https_port $HTTPS_PORT} \
${OPTS:+$OPTS}
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment