#!/bin/bash

set -e

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

source /var/vcap/packages/pid_utils_revok/pid_utils.sh

case $1 in

  start)
    pid_guard $PIDFILE "revok"

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

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

    mkdir -p <%= p("revok.work_dir") %>
    chown -R vcap:vcap <%= p("revok.work_dir") %>

    echo $$ > $PIDFILE
    chown -R vcap:vcap $PIDFILE

    exec chpst -u vcap:vcap -L $PIDFILE /var/vcap/packages/cred-alert/bin/revok-worker \
        --config-file /var/vcap/jobs/revok/config/config.yml                           \
        1>>$LOG_DIR/revok.stdout.log                                                   \
        2>>$LOG_DIR/revok.stderr.log

    ;;

  stop)
    kill_and_wait $PIDFILE

    ;;

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

    ;;

esac

#!/bin/bash

set -e

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

source /var/vcap/packages/pid_utils_revok/pid_utils.sh

case $1 in

  start)
    if [ -f "$PIDFILE" ]; then
      echo "pidfile already exists; exiting"
      exit 1
    fi

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

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

    mkdir -p <%= p("revok.work_dir") %>
    chown -R vcap:vcap <%= p("revok.work_dir") %>

    echo $$ > $PIDFILE
    chown -R vcap:vcap $PIDFILE

    exec chpst -u vcap:vcap -L $PIDFILE /var/vcap/packages/cred-alert/bin/revok-worker \
        --config-file /var/vcap/jobs/revok/config/config.yml                           \
        1>>$LOG_DIR/revok.stdout.log                                                   \
        2>>$LOG_DIR/revok.stderr.log

    ;;

  stop)
    kill_and_wait $PIDFILE

    ;;

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

    ;;

esac

Remove pid_guard from revok worker
Remove pid_guard from revok worker

Add simple check for existing pidfile and bail when it exists. chpst -L
will handle locking the pidfile.
