Skip to content

Instantly share code, notes, and snippets.

@davidgiesberg
Forked from erickr/statsd.init.sh
Created September 21, 2012 20:16

Revisions

  1. davidgiesberg revised this gist Sep 21, 2012. 2 changed files with 54 additions and 79 deletions.
    79 changes: 0 additions & 79 deletions statsd.init.sh
    Original file line number Diff line number Diff line change
    @@ -1,79 +0,0 @@
    #!/bin/bash
    #
    # StatsD
    #
    # chkconfig: 3 50 50
    # description: StatsD init.d
    . /lib/lsb/init-functions

    prog=statsd
    STATSDDIR=/opt/statsd
    statsd=stats.js
    LOG=/var/log/statsd.log
    ERRLOG=/var/log/statsderr.log
    CONFFILE=${STATSDDIR}/conf.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
    log_failure_msg "PID file exists for statsd"
    RETVAL=1
    else
    # Run as process
    /usr/local/bin/node ${statsd} ${CONFFILE} >> ${LOG} 2>> ${ERRLOG} &
    RETVAL=$?

    # Store PID
    echo $! > ${pidfile}

    # Success
    [ $RETVAL = 0 ] && log_success_msg "statsd started"
    fi

    echo
    return $RETVAL
    }

    stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${pidfile} && log_success_msg "statsd stopped"
    }

    # 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
    54 changes: 54 additions & 0 deletions statsd.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/bin/bash
    #
    # StatsD
    #
    # chkconfig: 3 50 50
    # description: StatsD init.d
    . /lib/lsb/init-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
    USER=www-data
    NODE=/usr/local/bin/node
    RETVAL=0
    STOP_TIMEOUT=${STOP_TIMEOUT-10}

    start() {
    log_daemon_msg "Starting $prog"
    start-stop-daemon --start --oknodo --quiet --background --make-pidfile -p ${pidfile} -d ${STATSDDIR} --chuid ${USER} --exec ${NODE} -- ${statsd} ${CONFFILE}
    log_end_msg $?
    }

    stop() {
    log_daemon_msg "Stopping $prog"
    start-stop-daemon --stop --oknodo --quiet -p ${pidfile} --exec ${NODE} --retry TERM/10/KILL/5
    log_end_msg $?
    }

    # See how we were called.
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status_of_proc ${NODE} ${prog} -p ${pidfile}
    ;;
    restart)
    stop
    start
    ;;
    *)
    echo $"Usage: $prog {start|stop|restart|status}"
    exit 1
    esac

    exit $RETVAL
  2. @erickr erickr revised this gist Oct 30, 2011. 3 changed files with 8 additions and 170 deletions.
    97 changes: 0 additions & 97 deletions README.markdown
    Original file line number Diff line number Diff line change
    @@ -1,97 +0,0 @@

    # Found from https://gist.github.com/889297
    # 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
    65 changes: 0 additions & 65 deletions carbon.init.sh
    Original file line number Diff line number Diff line change
    @@ -1,65 +0,0 @@
    #!/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
    16 changes: 8 additions & 8 deletions statsd.init.sh
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,14 @@
    #
    # chkconfig: 3 50 50
    # description: StatsD init.d
    . /etc/rc.d/init.d/functions
    . /lib/lsb/init-functions

    prog=statsd
    STATSDDIR=/opt/statsd
    statsd=./stats.js
    statsd=stats.js
    LOG=/var/log/statsd.log
    ERRLOG=/var/log/statsderr.log
    CONFFILE=${STATSDDIR}/local.js
    CONFFILE=${STATSDDIR}/conf.js
    pidfile=/var/run/statsd.pid
    lockfile=/var/lock/subsys/statsd
    RETVAL=0
    @@ -23,18 +23,18 @@ start() {

    # See if it's already running. Look *only* at the pid file.
    if [ -f ${pidfile} ]; then
    failure "PID file exists for statsd"
    log_failure_msg "PID file exists for statsd"
    RETVAL=1
    else
    # Run as process
    ${statsd} ${CONFFILE} >> ${LOG} 2>> ${ERRLOG} &
    /usr/local/bin/node ${statsd} ${CONFFILE} >> ${LOG} 2>> ${ERRLOG} &
    RETVAL=$?

    # Store PID
    echo $! > ${pidfile}

    # Success
    [ $RETVAL = 0 ] && success "statsd started"
    [ $RETVAL = 0 ] && log_success_msg "statsd started"
    fi

    echo
    @@ -46,7 +46,7 @@ stop() {
    killproc -p ${pidfile}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${pidfile}
    [ $RETVAL = 0 ] && rm -f ${pidfile} && log_success_msg "statsd stopped"
    }

    # See how we were called.
    @@ -76,4 +76,4 @@ case "$1" in
    exit 1
    esac

    exit $RETVAL
    exit $RETVAL
  3. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 97 additions and 0 deletions.
    97 changes: 97 additions & 0 deletions README.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,97 @@

    # Found from https://gist.github.com/889297
    # 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
  4. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion carbon.init.sh
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ start() {
    stop() {
    echo -n $"Stopping $prog: "

    PYTHONPATH=/usr/local/lib/python2.6/dist-packages/ /opt/graphite/bin/carbon-cache.py stop
    PYTHONPATH=/usr/local/lib/python2.6/dist-packages/ /opt/graphite/bin/carbon-cache.py stop > /dev/null 2>&1
    RETVAL=$?

    if [ $RETVAL = 0 ]; then
  5. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions carbon.init.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    #!/bin/bash
    #
    # StatsD
    # Carbon (part of Graphite)
    #
    # chkconfig: 3 50 50
    # description: StatsD init.d
    # description: Carbon init.d
    . /etc/rc.d/init.d/functions

    prog=carbon
  6. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 65 additions and 0 deletions.
    65 changes: 65 additions & 0 deletions carbon.init.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    #!/bin/bash
    #
    # StatsD
    #
    # chkconfig: 3 50 50
    # description: StatsD 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
    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
  7. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions statsd.init.sh
    Original file line number Diff line number Diff line change
    @@ -18,10 +18,10 @@ RETVAL=0
    STOP_TIMEOUT=${STOP_TIMEOUT-10}

    start() {
    echo -n $"Starting $prog: "
    echo -n $"Starting $prog: "
    cd ${STATSDDIR}

    # See if it's already running. Look *only* at the pid file.
    # See if it's already running. Look *only* at the pid file.
    if [ -f ${pidfile} ]; then
    failure "PID file exists for statsd"
    RETVAL=1
    @@ -34,11 +34,11 @@ start() {
    echo $! > ${pidfile}

    # Success
    [ $RETVAL = 0 ] && success "statsd started"
    [ $RETVAL = 0 ] && success "statsd started"
    fi

    echo
    return $RETVAL
    return $RETVAL
    }

    stop() {
    @@ -58,7 +58,7 @@ case "$1" in
    stop
    ;;
    status)
    status -p ${pidfile} ${prog}
    status -p ${pidfile} ${prog}
    RETVAL=$?
    ;;
    restart)
    @@ -76,4 +76,4 @@ case "$1" in
    exit 1
    esac

    exit $RETVAL
    exit $RETVAL
  8. @lukemorton lukemorton renamed this gist Jul 8, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions statsd.init
    Original file line number Diff line number Diff line change
    @@ -33,8 +33,8 @@ start() {
    # Store PID
    echo $! > ${pidfile}

    # Success if touch file created
    [ $RETVAL = 0 ] && touch ${lockfile} && success "statsd started"
    # Success
    [ $RETVAL = 0 ] && success "statsd started"
    fi

    echo
    @@ -46,7 +46,7 @@ stop() {
    killproc -p ${pidfile}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    [ $RETVAL = 0 ] && rm -f ${pidfile}
    }

    # See how we were called.
  10. @lukemorton lukemorton revised this gist Jul 8, 2011. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions statsd.init
    Original file line number Diff line number Diff line change
    @@ -17,11 +17,6 @@ lockfile=/var/lock/subsys/statsd
    RETVAL=0
    STOP_TIMEOUT=${STOP_TIMEOUT-10}


    # The semantics of these two functions differ from the way apachectl does
    # things -- attempting to start while running is a failure, and shutdown
    # when not running is also a failure. So we just do it the way init scripts
    # are expected to behave here.
    start() {
    echo -n $"Starting $prog: "
    cd ${STATSDDIR}
    @@ -46,9 +41,6 @@ start() {
    return $RETVAL
    }

    # When stopping httpd a delay (of default 10 second) is required
    # before SIGKILLing the httpd parent; this gives enough time for the
    # httpd parent to SIGKILL any errant children.
    stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile}
  11. @lukemorton lukemorton created this gist Jul 8, 2011.
    87 changes: 87 additions & 0 deletions statsd.init
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,87 @@
    #!/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}


    # The semantics of these two functions differ from the way apachectl does
    # things -- attempting to start while running is a failure, and shutdown
    # when not running is also a failure. So we just do it the way init scripts
    # are expected to behave here.
    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 if touch file created
    [ $RETVAL = 0 ] && touch ${lockfile} && success "statsd started"
    fi

    echo
    return $RETVAL
    }

    # When stopping httpd a delay (of default 10 second) is required
    # before SIGKILLing the httpd parent; this gives enough time for the
    # httpd parent to SIGKILL any errant children.
    stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${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