Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created July 8, 2011 14:44
Show Gist options
  • Save lukemorton/1071989 to your computer and use it in GitHub Desktop.
Save lukemorton/1071989 to your computer and use it in GitHub Desktop.
init.d file for statsd and carbon on rhel

Customised by Luke Morton

Ideally do this as SUDO

yum install -y git gcc gcc-c++ zlib-devel curl curl-devel openssl

Install node

wget http://nodejs.org/dist/node-v0.4.9.tar.gz
tar xvf node-v0.4.9.tar.gz
pushd node-v0.4.9
./configure
make
make install
popd
rm -rf node-v0.4.9*

install npm

curl http://npmjs.org/install.sh | sh

--- Install Graphite dependencies ---

yum install -y pycairo mod_python Django python-ldap python-memcached python-sqlite2 \
			   bitmap bitmap-fonts python-devel python-crypto pyOpenSSL zope

--- Install Whisper - Graphite's DB system ---

wget "http://launchpad.net/graphite/1.0/0.9.7/+download/whisper-0.9.7-1.noarch.rpm"
rpm -Uvh whisper-0.9.7-1.noarch.rpm
rm -rf whisper*.rpm

-- Install Carbon - the Graphite back-end ---

wget "http://launchpad.net/graphite/1.0/0.9.7/+download/carbon-0.9.7-1.noarch.rpm"
rpm -Uvh carbon-0.9.7-1.noarch.rpm
cp /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
cp /opt/graphite/conf/storage-schemas.conf.example /opt/graphite/conf/storage-schemas.conf
rm -rf carbon*.rpm

--- Install Twisted ---

wget http://pypi.python.org/packages/source/T/Twisted/Twisted-10.2.0.tar.bz2
tar jxf Twisted-10.2.0.tar.bz2
pushd Twisted-10.2.0
python setup.py install
popd
rm -rf Twisted-10.2.0*

--- Install Graphite ---

wget "http://launchpad.net/graphite/1.0/0.9.7/+download/graphite-web-0.9.7c-1.noarch.rpm"
rpm -Uvh graphite-web-0.9.7c-1.noarch.rpm
rm -rf graphite-web*.rpm

Add 8125:udp to firewall

copy the local_settings example file to creating the app's settings

this is where both carbon federation and authentication is configured

cp /opt/graphite/webapp/graphite/local_settings.py.example \
   /opt/graphite/webapp/graphite/local_settings.py

===== BEGIN MANUAL STEP =====

run syncdb to setup the db and prime the authentication model (if you're using the DB model)

python /opt/graphite/webapp/graphite/manage.py syncdb

Create super user

===== END MANUAL STEP =====

change ownership of the storage folder to the Apache user/group

chown -R apache:apache /opt/graphite/storage/

Config graphite /opt/graphite/conf

Set up init.d

wget https://gist.github.com/raw/1071989/32b8da693933ccc5b04445c13ec280a622f61400/carbon.init.sh
mv carbon.init.sh /etc/init.d/carbon
chmod 0755 /etc/init.d/carbon
chkconfig --add carbon

Add virtual host to apache.conf

service httpd start

--- Install StatsD ---

cd /opt
git clone git://github.com/etsy/statsd.git
cd statsd

copy the the statsd config example to create the config file

unless you used non-default ports for some other feature of the system, the defaults in the config file are fine

cp exampleConfig.js local.js

Set up init.d

wget https://gist.github.com/raw/1071989/c81cb3e25c3a8ed5426572474344e3f8eb0c6e53/statsd.init.sh
mv statsd.init.sh /etc/init.d/statsd
chmod 0755 /etc/init.d/statsd
chkconfig --add statsd
#!/bin/bash
#
# Carbon (part of Graphite)
#
# chkconfig: 3 50 50
# description: Carbon init.d
. /etc/rc.d/init.d/functions
prog=carbon
RETVAL=0
start() {
echo -n $"Starting $prog: "
PYTHONPATH=/usr/local/lib/python2.6/dist-packages/ /opt/graphite/bin/carbon-cache.py start
RETVAL=$?
if [ $RETVAL = 0 ]; then
success "carbon started"
else
failure "carbon failed to start"
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
PYTHONPATH=/usr/local/lib/python2.6/dist-packages/ /opt/graphite/bin/carbon-cache.py stop > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL = 0 ]; then
success "carbon stopped"
else
failure "carbon failed to stop"
fi
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
PYTHONPATH=/usr/local/lib/python2.6/dist-packages/ /opt/graphite/bin/carbon-cache.py status
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
#!/bin/bash
#
# StatsD
#
# chkconfig: 3 50 50
# description: StatsD init.d
. /etc/rc.d/init.d/functions
prog=statsd
STATSDDIR=/opt/statsd
statsd=./stats.js
LOG=/var/log/statsd.log
ERRLOG=/var/log/statsderr.log
CONFFILE=${STATSDDIR}/local.js
pidfile=/var/run/statsd.pid
lockfile=/var/lock/subsys/statsd
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
start() {
echo -n $"Starting $prog: "
cd ${STATSDDIR}
# See if it's already running. Look *only* at the pid file.
if [ -f ${pidfile} ]; then
failure "PID file exists for statsd"
RETVAL=1
else
# Run as process
${statsd} ${CONFFILE} >> ${LOG} 2>> ${ERRLOG} &
RETVAL=$?
# Store PID
echo $! > ${pidfile}
# Success
[ $RETVAL = 0 ] && success "statsd started"
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${pidfile}
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} ${prog}
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|status}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment