#!/bin/bash

set -e -x

JOB_DIR=/var/vcap/jobs/bits-service
RUN_DIR=/var/vcap/sys/run/nginx_bits
LOG_DIR=/var/vcap/sys/log/nginx_bits
PIDFILE=$RUN_DIR/statsd_pipe.pid
export PATH=/var/vcap/packages/socat/bin:$PATH

source /var/vcap/packages/bits-common/pid_utils.sh
source ${JOB_DIR}/bin/syslog_utils.sh
tee_output_to_sys_log_and_file "${LOG_DIR}" "$(basename "$0")"

case $1 in
  start)
    mkdir -p $RUN_DIR
    mkdir -p $LOG_DIR

    chown vcap:vcap $RUN_DIR
    chown vcap:vcap $LOG_DIR

    pid_guard $PIDFILE "statsd_pipe"

    $JOB_DIR/bin/statsd_pipe '<%= p("bits-service.nginx.metrics_private_log_destination") %> <%= p("bits-service.nginx.metrics_public_log_destination") %>' 2>&1 &
    echo $! > $PIDFILE

    ;;
  stop)
    # force kill immediately; drain script should have already run
    kill_and_wait $PIDFILE
    ;;
  *)
    echo "Usage: statsd_pipe_ctl {start|stop}"
    ;;
esac
#!/bin/bash

set -e -x

JOB_DIR=/var/vcap/jobs/bits-service
RUN_DIR=/var/vcap/sys/run/nginx_bits
LOG_DIR=/var/vcap/sys/log/nginx_bits
PIDFILE=$RUN_DIR/statsd_pipe.pid
export PATH=/var/vcap/packages/socat/bin:$PATH

source /var/vcap/packages/bits-common/pid_utils.sh
source ${JOB_DIR}/bin/syslog_utils.sh
tee_output_to_sys_log_and_file "${LOG_DIR}" "$(basename "$0")"

case $1 in
  start)
    mkdir -p $RUN_DIR
    mkdir -p $LOG_DIR

    chown vcap:vcap $RUN_DIR
    chown vcap:vcap $LOG_DIR

    pid_guard $PIDFILE "statsd_pipe"

    echo $$ > $PIDFILE
    exec $JOB_DIR/bin/statsd_pipe '<%= p("bits-service.nginx.metrics_private_log_destination") %> <%= p("bits-service.nginx.metrics_public_log_destination") %>' 2>&1

    ;;
  stop)
    # force kill immediately; drain script should have already run
    kill_and_wait $PIDFILE
    ;;
  *)
    echo "Usage: statsd_pipe_ctl {start|stop}"
    ;;
esac
Use exec when starting statsd_pipe
Use exec when starting statsd_pipe

This is an attempt to fix the monit setup for statsd_pipe. We've seen a huge number of statsd_pipe processes in AWS, which suggests that monit fails to deal properly with those processes.
