Skip to content

Instantly share code, notes, and snippets.

@maanas
Forked from lukemorton/README.markdown
Created October 15, 2012 08:11
Show Gist options
  • Save maanas/3891354 to your computer and use it in GitHub Desktop.
Save maanas/3891354 to your computer and use it in GitHub Desktop.
Running Carbon and StatsD as Daemon on Centos init.d file for statsd and carbon on Centos

Forged by Maanas Royy from command logs

#Centos 6.3 x86_64

Install the required dependencies

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

Install node

git clone git://github.com/joyent/node.git
cd node
./configure
make
make install

Make sym link to add node and npm in path

    ln -s /opt/node/bin/node /usr/local/bin
ln -s /opt/node/bin/npm /usr/loca/bin/npm

--- 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 Python setup tools & pip ---

    yum install python-setuptools
    easy_install pip

--- 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 Graphite back-end ---

    pip install whisper
    pip install carbon
    pip install twisted
    pip install django==1.3
    pip install graphite-webapp

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 Nginx user/group

chown -R www-data:nobody /opt/graphite/storage/

Config graphite /opt/graphite/conf

Set up init.d

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

--- 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 localConfig.js

Set up init.d

https://raw.github.com/gist/3891354/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}/localConfig.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
node ${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