Skip to content

Instantly share code, notes, and snippets.

@pkittenis

pkittenis/carbon-c-relay

Last active Aug 29, 2015
Embed
What would you like to do?
Carbon-c-relay
#!/bin/bash
#
# Init script for carbon-c-relay
#
# chkconfig: 345 80 20
# description: Carbon-c-relay is an alternative graphite relay \
# as a replacement for the built in carbon-relay. It provides \
# vastly better performance compared to the built in relay \
# in a multi-threaded process.
# processname: carbon-c-relayd"
#
SERVICE="carbon-c-relay"
PID_FILE="/var/run/carbon-c-relay.pid"
DAEMON="<path>/carbon-c-relayd"
_LOG_DIR="<path>/carbon-c-relay"
start() {
if [ -f ${PID_FILE} ]; then
pid=`cat ${PID_FILE}`
ps -p ${pid} > /dev/null
if [[ $? -eq 0 ]]; then
echo "Proccess $pid at $PID_FILE still running.."
return
fi
fi
echo "Starting ${SERVICE}: "
mkdir -p ${_LOG_DIR}
chown -R : ${_LOG_DIR}
ulimit -n 65534
/sbin/start-stop-daemon --start -b --oknodo -p ${PID_FILE} -m -x ${DAEMON}
return $?
}
stop() {
echo "Stopping ${SERVICE}: "
/sbin/start-stop-daemon --stop --oknodo --retry=TERM/30/KILL/5 -p ${PID_FILE}
return $?
}
status() {
if [ ! -f ${PID_FILE} ]; then
echo "Stopped: No pidfile ${PID_FILE}"
exit 3
fi
pid=`cat ${PID_FILE}`
ps -p ${pid} > /dev/null
if [ $? -eq 0 ]; then
echo "Running"
exit 0
else
echo "Stopped"
exit 3
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
if [ $? -ne 0 ]; then
echo "Could not stop service, not starting"
exit 1
fi
sleep 1
start
;;
status)
status
;;
*)
echo "Usage: $(basename ${0}) {start|stop|restart|status}"
exit 1
;;
esac
#!/bin/bash
#
# Startup script for carbon-c-relay
#
CARBON_C_CMD="<%= @appDir %>/bin/relay"
CFG_FILE="<%= @config_file %>"
_LOG_DIR="<%= @logDir %>/<%= @service_name %>"
LOG_FILE="${_LOG_DIR}/<%= @service_name %>.log"
LOG_ERR="${_LOG_DIR}/<%= @service_name %>.err"
NUM_WORKERS=4
PORT=<%= @port %>
MAX_QUEUE_SIZE="<%= @relayMaxQueueSize %>"
BATCH_SIZE="<%= @relayBatchSize %>"
mkdir -p ${_LOG_DIR}
${CARBON_C_CMD} -f ${CFG_FILE} -w ${NUM_WORKERS} -q ${MAX_QUEUE_SIZE} -b ${BATCH_SIZE} -p ${PORT} >>"${LOG_FILE}" 2>>"${LOG_ERR}" &
# Capture the child process PID
CHILD="$!"
# Kill the child process when start-stop-daemon sends us a kill signal
trap "kill $CHILD" exit INT TERM
# Wait for child process to exit
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.