#!/command/with-contenv /bin/bash
# shellcheck disable=SC1091,SC2068
# =============================
# GPUStack server longrun service
# =============================

source /etc/profile
SCRIPT_ROOT=/etc/s6-overlay/scripts
source "$SCRIPT_ROOT/base.sh"

ARGS_FILE="/run/gpustack/args"

# Read arguments from the args file if it exists and is not empty
set --
if [ -s "$ARGS_FILE" ]; then
    while IFS= read -r line || [ -n "$line" ]; do
        [ -z "$line" ] && continue
        set -- "$@" "$line"
    done < "$ARGS_FILE"
fi

echo "[INFO] Starting gpustack server."
if [ "$#" -gt 0 ]; then
    exec gpustack start "$@"
else
    exec gpustack start
fi
