#!/usr/bin/env bash # Read parameters from configuration file (overlay or special mount or regular) while read ENV_VAR ; do export ${ENV_VAR} done < security/sensitive-config.ini set -x export PYTHONPATH="/opt/SfaxWare" ################################ root section ################################ if test `whoami` = root then trap 'pkill su' SIGTERM # Execute initialization that requires root access rights if test -z ${LOG_FILE} then ln -sf /dev/pts/0 /var/log/fastapi-readme.log elif test -L ${LOG_FILE} then rm -f ${LOG_FILE} fi # Execute this script as a regular user with right to write to our console su -P sfaxware $0 & # Wait for any of launched jobs to exit wait -f -n # Execute finalization that requires root access rights exit fi ############################## Non root section ############################## CONTINUE=true trap 'CONTINUE=false ; pkill -f "appBackground.jar|predict.py|bnc-2.13.0|api.py"' SIGTERM # Retrieve data stored in a git repository if test -n "${DATA_SSH_KEY}" then mkdir -p ${HOME}/.ssh test -z "${DATA_SSH_KEY}" || echo ${DATA_SSH_KEY} | tr 'ยง' '\n' > ${HOME}/.ssh/id_rsa chmod go= ${HOME}/.ssh/id_rsa ssh -o StrictHostKeyChecking=accept-new `echo "${DATA_GIT_URL}" | sed -e 's/.* //' -e 's/:.*//'` if test -d ${CACHE}/.git then HISTORY=`git -C ${CACHE} log -1 --after="2 hour ago"` if test -z "${HISTORY}" then rm -f ${CACHE}/.git/index.lock git -C ${CACHE} remote update -p git -C ${CACHE} reset --hard origin/master fi else rm -rf ${CACHE} git -C ${DATA_DIR} clone ${DATA_GIT_URL} fi git -C ${CACHE} config user.email 'robot@q-ai.org' git -C ${CACHE} config user.name 'Q-AI Robot' fi while ${CONTINUE} do echo "*******************************************************************" if ! pgrep -f api.py > /dev/null then echo "* Micro service api.py restarted on `date -Is` *" ./sfxpkg/api.py \ --port ${HTTP_PORT:-7860} \ --host 0.0.0.0 \ & fi echo "*******************************************************************" # Wait for any of launched jobs to exit wait -f -n done