<commit_before>#!/bin/sh
# !!! generated by puppet !!!

### BEGIN INIT INFO
# chkconfig: 2345 99 80
# Provides: carbon-aggregator
# Required-Start: $remote_fs $network $time
# Required-Stop: $remote_fs $network
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: Start/Stop carbon-aggregator
# Description: Enables Graphites carbon-aggregator data aggregation engine
### END INIT INFO

PYTHON_CMD='python -W ignore'
CARBON_CONF='/opt/graphite/conf/carbon.conf'

OPERATION="$1"
if [ $# -gt 1 ]; then
    shift
    INSTANCES=$@
else
    INSTANCES=$(awk '$1 ~ /^\[aggregator/ { sub("\[aggregator:?","", $1); sub("]$","", $1); if ($1 == "") { print "a"} else { print $1} }' "${CARBON_CONF}")
fi

case "${OPERATION}" in
    start)
        for instance in ${INSTANCES}; do
            ${PYTHON_CMD} /opt/graphite/bin/carbon-aggregator.py --instance=${instance} start
        done
        ;;
    stop)
        for instance in ${INSTANCES}; do
            ${PYTHON_CMD} /opt/graphite/bin/carbon-aggregator.py --instance=${instance} stop
        done
        ;;
    status)
        for instance in ${INSTANCES}; do
            ${PYTHON_CMD} /opt/graphite/bin/carbon-aggregator.py --instance=${instance} status
        done
        ;;
    restart)
        $0 stop ; sleep 3 ; $0 start
        RC=$?
        exit $RC
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status} [instance instance ...]"
        exit 1
        ;;
esac

exit
<commit_msg>complete new init script for aggregator<commit_after>#!/bin/sh
# !!! generated by puppet !!!

# chkconfig: 345 80 20
# description: Start/Stop carbon-aggregator
# processname: carbon-cache
# config: /opt/graphite/conf/carbon.conf

### BEGIN INIT INFO
# Provides: carbon-aggregator
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop carbon-aggregator
# Description: Enables Graphites carbon-aggregator data aggregation engine
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

PYTHON_CMD='python -W ignore'
CARBON_DAEMON="aggregator"
GRAPHITE_DIR="/opt/graphite"
INSTANCES=`grep "^\[${CARBON_DAEMON}" ${GRAPHITE_DIR}/conf/carbon.conf | cut -d \[ -f 2 | cut -d \] -f 1 | cut -d : -f 2`
pidfile=""

start()
{
    for INSTANCE in ${INSTANCES}; do
        if [ "${INSTANCE}" == "${CARBON_DAEMON}" ]; then
            INSTANCE="a";
        fi;
        pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid
        prog=carbon-${CARBON_DAEMON}-${INSTANCE}
        # check if instance is already running
        rh_status_q && continue
        
        ${PYTHON_CMD} ${GRAPHITE_DIR}/bin/carbon-${CARBON_DAEMON}.py --instance=${INSTANCE} start;
        retval=$?
        pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid
        echo -n $"Starting carbon-${CARBON_DAEMON}:${INSTANCE}..."
        if [ rh_status_q ]; then
            touch /var/lock/subsys/carbon-${CARBON_DAEMON}-${INSTANCE}
            echo_success
            echo
        else
            echo_failure
            echo
            exit 1
        fi
    done
    return $retval
}

stop()
{
    for INSTANCE in ${INSTANCES}; do
        if [ "${INSTANCE}" == "${CARBON_DAEMON}" ]; then
            INSTANCE="a";
        fi;
        pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid
        prog=carbon-${CARBON_DAEMON}-${INSTANCE}
        # check if instance is already stopped
        rh_status_q || continue
        
        ${PYTHON_CMD} ${GRAPHITE_DIR}/bin/carbon-${CARBON_DAEMON}.py --instance=${INSTANCE} stop;
        sleep 3
        while [ -f ${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid ]; do
            echo "waiting another 5 secs for carbon-${CARBON_DAEMON}-${INSTANCE} to stop"
            sleep 5
            #TODO: add timer to prevend endless waiting
        done
        rm -f /var/lock/subsys/carbon-${CARBON_DAEMON}-${INSTANCE}
        echo -n $"Stopping carbon-${CARBON_DAEMON}:${INSTANCE}..."
        echo_success
        echo
    done
    return 0
}

restart() {
    # To be sure that at least one intance is always running during restart,
    # we will restart one instance at a time.
    for INSTANCE in ${INSTANCES}; do
        if [ "${INSTANCE}" == "${CARBON_DAEMON}" ]; then
            INSTANCE="a";
        fi;
        pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid
        prog=carbon-cache-${INSTANCE}
        
        ${PYTHON_CMD} ${GRAPHITE_DIR}/bin/carbon-${CARBON_DAEMON}.py --instance=${INSTANCE} stop;
        sleep 3
        while [ -f ${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid ]; do
            echo "waiting another 5 secs for carbon-${CARBON_DAEMON}-${INSTANCE} to stop"
            sleep 5
            #TODO: add timer to prevend endless waiting
        done
        rm -f /var/lock/subsys/carbon-${CARBON_DAEMON}-${INSTANCE}
        echo -n $"Stopping carbon-${CARBON_DAEMON}:${INSTANCE}..."
        echo_success
        echo
        
        ${PYTHON_CMD} ${GRAPHITE_DIR}/bin/carbon-${CARBON_DAEMON}.py --instance=${INSTANCE} start;
        retval=$?
        pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid
        echo -n $"Starting carbon-${CARBON_DAEMON}:${INSTANCE}..."
        if [ rh_status_q ]; then
            touch /var/lock/subsys/carbon-${CARBON_DAEMON}-${INSTANCE}
            echo_success
            echo
        else
            echo_failure
            echo
            exit 1
        fi
    done
    return $retval
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    status -p $pidfile $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        $1
        ;;
    stop)
        $1
		;;
    restart)
        $1
        ;;
    reload)
        $1
        ;;
    force-reload)
        force_reload
        ;;
    condrestart|try-restart)
        # TODO: bad behavior. only checking instance "a" at the moment
        pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-a.pid
        prog=carbon-${CARBON_DAEMON}-a
        rh_status_q || exit 0
        restart
        ;;
    status)
        for INSTANCE in ${INSTANCES}; do
            if [ "${INSTANCE}" == "${CARBON_DAEMON}" ]; then
                INSTANCE="a";
            fi;
            pidfile=${GRAPHITE_DIR}/storage/carbon-${CARBON_DAEMON}-${INSTANCE}.pid
            prog=carbon-cache-${INSTANCE}
            rh_status
        done
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

{'fraction_non_alphanumeric': 0.14302812687013763, 'fraction_numerical': 0.009425493716337522, 'mean_word_length': 2.302865612648221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3389306', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2223, 'n_words': 483}