#!/bin/bash

set -e # exit immediately if a simple command exits with a non-zero status
set -u # report the usage of uninitialized variables

# Setup env vars and folders for the ctl script
source /var/vcap/jobs/cache/helpers/ctl_setup.sh 'cache' 'redis'

export LANG=en_US.UTF-8

case $1 in
  start)
    pid_guard $PIDFILE $JOB_NAME
    prep_system
    # Set limitations on system resources
    ulimit -n $JOB_ULIMIT_FILES
    exec chpst -u vcap:vcap redis-server \
      $JOB_DIR/config/redis.conf \
      >>$LOG_DIR/$JOB_NAME.log 2<&1
    ;;
  stop)
    kill_and_wait $PIDFILE
    ;;
  *)
    echo "Usage: ctl {start|stop}"
    ;;
esac
exit 0
