Skip to content

Instantly share code, notes, and snippets.

@agile
Created February 7, 2014 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agile/8872357 to your computer and use it in GitHub Desktop.
Save agile/8872357 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: druid_historical
# Required-Start: $local_fs $remote_fs $syslog $network
# Required-Stop: $local_fs $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts Druid historical service
# Description: start Druid historical service using start-stop-daemon
### END INIT INFO
#
# host & port for our listen socket
# set -u -x
shopt -s xpg_echo
shopt -s expand_aliases
trap "exit 1" 1 2 3 15
PORT=9081
HOST=stg-dn05.company.com:${PORT}
JMXPORT=19081
# JVM options
JVM_OPTS=""
JVM_OPTS+=" -d64 -Xmx25g -XX:MaxDirectMemorySize=25g"
JVM_OPTS+=" -Duser.timezone=UTC"
JVM_OPTS+=" -Dfile.encoding=UTF-8"
JVM_OPTS+=" -Ddruid.host=$HOST"
JVM_OPTS+=" -Ddruid.port=$PORT"
JVM_OPTS+=" -Dlog4j.configuration=file:///etc/druid/log4j.properties"
JVM_OPTS+=" -Djava.io.tmpdir=/home/druid/tmp"
JVM_OPTS+=" -Dcom.sun.management.jmxremote.port=$JMXPORT"
JVM_OPTS+=" -Dcom.sun.management.jmxremote.authenticate=false"
JVM_OPTS+=" -Dcom.sun.management.jmxremote.ssl=false"
CLASSPATH=""
# add hadoop if it exists
HADOOP=/usr/bin/hadoop
if [ -x ${HADOOP} ]; then
CLASSPATH+=":$(${HADOOP} classpath)"
fi
# build the classpath
CLASSPATH="/etc/druid/historical"
# Include selfcontained jars if we find them.. like if we built from source
# ./services/target/druid-services-0.6.57-SNAPSHOT-selfcontained.jar
# ./examples/target/druid-examples-0.6.57-SNAPSHOT-selfcontained.jar
# ./indexing-hadoop/target/druid-indexing-hadoop-0.6.57-SNAPSHOT-selfcontained.jar
# SELFCONT_SERVICES="$(ls /opt/druid/services/target/druid_services*selfcontained.jar 2>/dev/null)"
# if [ -n "${SELFCONT_SERVICES}" ]; then
# CLASSPATH+=":${SELFCONT_SERVICES}"
# fi
# SELFCONT_INDEXING="$(ls /opt/druid/indexing-hadoop/target/druid_indexing*selfcontained.jar 2>/dev/null)"
# if [ -n "${SELFCONT_INDEXING}" ]; then
# CLASSPATH+=":${SELFCONT_INDEXING}"
# fi
for SELF_CONT in `find /opt/druid -name "*selfcontained.jar" 2>/dev/null`; do
CLASSPATH+=":${SELF_CONT}"
done
CLASSPATH+=":/opt/druid/lib/*"
DRUID_SERVICE="io.druid.cli.Main server historical"
function running() {
/usr/bin/pgrep -f "${DRUID_SERVICE}" 2>&1 >/dev/null
return $?
}
function pid() {
/usr/bin/pgrep -f "${DRUID_SERVICE}" 2>/dev/null
}
function start() {
if running; then
echo "historical is already running, pid $(pid)"
return 1
else
CLI="exec /usr/bin/java $JVM_OPTS -cp $CLASSPATH ${DRUID_SERVICE} >> /var/log/druid/historical.log 2>&1 &"
echo -n "spawning druid historical service on ${PORT}, JMX on ${JMXPORT}... "
/bin/su - druid -c "${CLI}"
echo "historical started, pid: $(pid)"
return 0
fi
}
function stop() {
if running; then
echo -n "Stopping historical..."
/usr/bin/pkill -f "${DRUID_SERVICE}"
count=0
while running && [ "$count" -lt "60" ]; do
sleep 1
((count++))
done
if running; then
echo -n "being stubborn, trying -9.."
/usr/bin/pkill -9 -f "${DRUID_SERVICE}"
count=0
while running && [ "$count" -lt "60" ]; do
sleep 1
((count++))
done
fi
echo "stopped!"
else
echo "historical is not running"
fi
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
if running; then
pgrep -lf "${DRUID_SERVICE}"
else
echo "druid historical is not running"
fi
;;
*)
echo "USAGE: ${0} <start|restart|stop>"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment