#
# initfns:  Customize the behavior of the Aerospike daemon init scripts.
#

# Enable any requested library preloads:
if [[ $2 =~ jem$ ]]; then
  LD_PRELOAD=/opt/aerospike/lib/libjemalloc.so
  if [[ $2 =~ ^as ]]; then
    LD_PRELOAD=/opt/aerospike/lib/asmalloc.jem.so:$LD_PRELOAD
  else if [[ $2 =~ ^rz ]]; then
      export MALLOC_CONF=junk:true,redzone:true,abort:true
    fi
  fi
  echo "MALLOC_CONF = $MALLOC_CONF"
  echo Preload libraries: $LD_PRELOAD
fi

if [[ $3 =~ gdb ]]; then
  CMD="/opt/aerospike/bin/run-under-gdb $CMD"
else
  if [[ $3 =~ vg ]]; then
    CMD="valgrind --leak-check=full --suppressions=/etc/aerospike/valgrind.supp --db-attach=yes $CMD"
  else
    if [[ $3 =~ core ]]; then
      export DAEMON_COREFILE_LIMIT="unlimited"
    fi
  fi
fi
