#!/bin/bash

RUN_DIR=/var/vcap/sys/run/pinger
LOG_DIR=/var/vcap/sys/log/pinger
PIDFILE=${RUN_DIR}/pid

source /var/vcap/packages/common/utils.sh

case $1 in

  start)
    pid_guard $PIDFILE "ping-app"

    mkdir -p $RUN_DIR $LOG_DIR
    chown -R vcap:vcap $RUN_DIR $LOG_DIR

    echo $$ > $PIDFILE

    exec /var/vcap/packages/ping-app/bin/pinger \
    --listenPort <%= p('port') %> \
    --interval <%= p('ping_interval') %> \
    <% pinger_addresses = link('pinger').instances.map(&:address) -%>
    <% (pinger_addresses - [spec.address]).each do |address| -%>
    --address <%= address %>:<%= p('port') %> \
    <% end -%>
    1>>$LOG_DIR/stdout.log \
    2>>$LOG_DIR/stderr.log

    ;;

  stop)
    kill_and_wait $PIDFILE

    ;;

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

esac

#!/bin/bash

RUN_DIR=/var/vcap/sys/run/ping-app
LOG_DIR=/var/vcap/sys/log/ping-app
PIDFILE=${RUN_DIR}/pid

source /var/vcap/packages/common/utils.sh

case $1 in

  start)
    pid_guard $PIDFILE "ping-app"

    mkdir -p $RUN_DIR $LOG_DIR
    chown -R vcap:vcap $RUN_DIR $LOG_DIR

    echo $$ > $PIDFILE

    exec /var/vcap/packages/ping-app/bin/pinger \
    --listenPort <%= p('port') %> \
    --interval <%= p('ping_interval') %> \
    <% pinger_addresses = link('pinger').instances.map(&:address) -%>
    <% (pinger_addresses - [spec.address]).each do |address| -%>
    --address <%= address %>:<%= p('port') %> \
    <% end -%>
    1>>$LOG_DIR/stdout.log \
    2>>$LOG_DIR/stderr.log

    ;;

  stop)
    kill_and_wait $PIDFILE

    ;;

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

esac

Change job name to ping-app
Change job name to ping-app
