#!/bin/bash
# 
# This is the service control script for SkyForm CRV server
#

# -------------- Modify the following lines
. /opt/skyformai/etc/aip.sh
CRV_TOP=$CB_ENVDIR/skyformcrv
CRV_SERVICE=$CRV_TOP/sbin
TOKEN_DIR=/var/run/crv/.tokens
LOG_DIR=/var/log/crv
LOG_FILE=$LOG_DIR/crv.log
CRV_PORT=16000
SSLONLY=0
CRV_SSL_KEY=$CRV_TOP/certs/ca.key
CRV_SSL_CERT=$CRV_TOP/certs/ca.crt
CRV_WEB=$CRV_TOP/html
# ---------------------------------------------

if [ ! -d $TOKEN_DIR ]; then
    mkdir -p $TOKEN_DIR
    chmod 777 $TOKEN_DIR
fi

if [ ! -d $LOG_DIR ]; then
    mkdir -p $LOG_DIR
fi

if [ -f $LOG_FILE ]; then
    rm -f $LOG_FILE
fi
if [ $SSLONLY == '1' ]; then
    sslonly='--ssl-only'
fi
exec $CRV_SERVICE/crvrun --log-file $LOG_FILE \
--token-plugin TokenFile --token-source $TOKEN_DIR --cert=$CRV_SSL_CERT \
--key=$CRV_SSL_KEY --web=$CRV_WEB $sslonly 0.0.0.0:$CRV_PORT
