#!/usr/bin/env bash
#
# This is a simpler version of the `start` script and is intended for
# use as a simple configuration as part of the
# docker/common/Dockerfile runtime-simple build configuration.
#
# TODO: Using this script may not be necessary. It could be integrated
# into the Dockerfile.
#

set -eo pipefail

SCRIPT_DIR="$(realpath $(dirname "${BASH_SOURCE[0]}"))"
export ROOT=$(realpath $SCRIPT_DIR/..)

: ${R_LIBS="$ROOT/lib"}
export R_LIBS

if [ "$1" = "-d" ]; then
   export DEBUG=1
fi

if [ ! -d "$ROOT/run" ]; then mkdir -p "$ROOT/run"; fi

# if ! redis-cli ping; then  redis-server & fi

R --slave --no-restore --vanilla \
  --file="$ROOT/conf/run_rcloud.R" \
  --args "$ROOT/conf/rserve.conf"
