#!/bin/bash

RUN_DIR=/var/vcap/sys/run/splunk-forwarder
LOG_DIR=/var/vcap/sys/log/splunk-forwarder
JOB_DIR=/var/vcap/jobs/splunk-forwarder
PACKAGE_DIR=/var/vcap/packages/splunk
PIDFILE=${RUN_DIR}/pid

case $1 in

  start)
    mkdir -p ${RUN_DIR} ${LOG_DIR}
    mkdir -p ${PACKAGE_DIR}/etc/system/local
    mkdir -p ${PACKAGE_DIR}/etc/apps/splunk_httpinput/local

    chown -R vcap:vcap ${RUN_DIR} ${LOG_DIR} ${PACKAGE_DIR}/

    echo $$ > ${PIDFILE}

    ln -fs ${JOB_DIR}/config/system_local/* ${PACKAGE_DIR}/etc/system/local/
    ln -fs ${JOB_DIR}/config/apps_splunk_httpinput_local/* ${PACKAGE_DIR}/etc/apps/splunk_httpinput/local/

    exec chpst -u vcap:vcap /var/vcap/packages/splunk/bin/splunk start --accept-license  --no-prompt --answer-yes\
      >>  $LOG_DIR/forwarder.stdout.log \
      2>> $LOG_DIR/forwarder.stderr.log

    ;;

  stop)
    /var/vcap/packages/splunk/bin/splunk stop
    rm -f $PIDFILE

    ;;

  *)
    echo "Usage: ctl {start|stop}" ;;

esac

#!/bin/bash

RUN_DIR=/var/vcap/sys/run/splunk-forwarder
LOG_DIR=/var/vcap/sys/log/splunk-forwarder
JOB_DIR=/var/vcap/jobs/splunk-forwarder
PACKAGE_DIR=/var/vcap/packages/splunk
PIDFILE=${RUN_DIR}/pid

case $1 in

  start)
    mkdir -p ${RUN_DIR} ${LOG_DIR}
    mkdir -p ${PACKAGE_DIR}/etc/system/local
    mkdir -p ${PACKAGE_DIR}/etc/apps/splunk_httpinput/local

    chown -R vcap:vcap ${RUN_DIR} ${LOG_DIR} ${PACKAGE_DIR}/

    echo $$ > ${PIDFILE}

    ln -fs ${JOB_DIR}/config/system_local/* ${PACKAGE_DIR}/etc/system/local/
    ln -fs ${JOB_DIR}/config/apps_splunk_httpinput_local/* ${PACKAGE_DIR}/etc/apps/splunk_httpinput/local/

    exec chpst -u vcap:vcap /var/vcap/packages/splunk/bin/splunk start --accept-license  --no-prompt --answer-yes\
      >>  $LOG_DIR/forwarder.stdout.log \
      2>> $LOG_DIR/forwarder.stderr.log

    ;;

  stop)
    exec chpst -u vcap:vcap /var/vcap/packages/splunk/bin/splunk stop
    rm -f $PIDFILE

    ;;

  restart)
    exec chpst -u vcap:vcap /var/vcap/packages/splunk/bin/splunk restart\
      >>  $LOG_DIR/forwarder.stdout.log \
      2>> $LOG_DIR/forwarder.stderr.log

  *)
    echo "Usage: ctl {start|stop|restart}" ;;

esac

Add restart command to ctl script
Add restart command to ctl script
