diff --git a/.gitignore b/.gitignore index 2f6f3051..ce7af1ec 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,6 @@ venv* cerfServer/.env* cerfServer/local_settings.py -downloads/ - # OS generated files .DS_Store Thumbs_db diff --git a/downloads/.dummy b/downloads/.dummy new file mode 100644 index 00000000..dc6888eb --- /dev/null +++ b/downloads/.dummy @@ -0,0 +1 @@ +.dummy file so we check commit the directory to avoid start-up error \ No newline at end of file diff --git a/runCerf.sh b/runCerf.sh index 308e4e65..edb42cc9 100755 --- a/runCerf.sh +++ b/runCerf.sh @@ -10,6 +10,56 @@ DATA_ASSIMILATION_REF='development' NGEN_FORCING_REF='development' EWTS_REF='development' +#======================================================================= +# Usage / help +# - Checked before anything else so it works without cerfserver.env, +# a venv, or AWS credentials being set up. +#======================================================================= +if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then + cat < | unset. Venv location, or + 'Docker' to skip local venv/AWS-check logic. + REQUIRED_PYTHON Required Python version, e.g. 3.11 or python3.11. + RUN_CERF_FLAG_DIRECTORY Directory for SHA/gage marker files (default ./). + FORCE_REINSTALL_VCS 1 to force reinstall of git-based dependencies. + DJANGO_SUPERUSER_EMAIL/ + DJANGO_SUPERUSER_PASSWORD Bootstrap a superuser if not already present. + CERF_ASGI / CERF_PRODUCTION + Set to 1 to launch Gunicorn+Uvicorn instead of + the Django dev server. + GUNICORN_WORKERS, GUNICORN_TIMEOUT, GUNICORN_BIND, + GUNICORN_MAX_REQUESTS, GUNICORN_MAX_REQUESTS_JITTER, + GUNICORN_GRACEFUL_TIMEOUT + Gunicorn tuning, used only when the ASGI + server is launched. +EOF + exit 0 +fi + #======================================================================= # Script must be sourced for 'activate' mode #======================================================================= @@ -310,6 +360,37 @@ run_manage_command() { } +#======================================================================= +# Function: gage_records_exist +# - Returns 0 if the gage table contains at least one record +# - Returns 10 if the gage table is empty +# - Returns 2 if Django could not perform the check +#======================================================================= +gage_records_exist() { + echo "Checking whether the gage table contains any records..." + + python "$SCRIPT_DIR/manage.py" shell -c ' +from calibration.models import Gage +raise SystemExit(0 if Gage.objects.exists() else 10) +' --verbosity 0 + + local status=$? + + case $status in + 0) + echo "The gage table contains records." + return 0 + ;; + 10) + echo "The gage table is empty." + return 10 + ;; + *) + echo "ERROR: Could not determine whether the gage table contains records." + return 2 + ;; + esac +} #======================================================================= # Function: generate_git_info @@ -793,6 +874,7 @@ fi #======================================================================= # Init data handling +# - Empty gage table => unconditional init_gages # - '--load-gages' or missing marker => unconditional init_gages # - Otherwise compare the stored and current fingerprints #======================================================================= @@ -801,9 +883,30 @@ GAGE_DATA_FLAG_FILE="${RUN_CERF_FLAG_DIRECTORY}/.load_gages" echo echo -------------------------------------------------------- -# Only load gage data if the flag is provided or the flag file doesn't exist. -# Also reload gage data if the input fingerprint has changed. -if [ "$LOAD_GAGE_DATA" = true ]; then +# Load gage data if the table is empty, the flag is provided, or the +# load-gages marker does not exist. Also reload if the inputs changed. +gage_records_exist +GAGE_RECORDS_STATUS=$? + +if [ $GAGE_RECORDS_STATUS -eq 2 ]; then + echo "ERROR: Could not check the gage table." + exit 1 +fi + +if [ $GAGE_RECORDS_STATUS -eq 10 ]; then + echo "Running init_gages because the gage table is empty." + + run_init_gages_and_store "" + status=$? + + if [ $status -ne 0 ]; then + echo "init_gages failed with exit code $status" + exit $status + fi + + touch "$GAGE_DATA_FLAG_FILE" + +elif [ "$LOAD_GAGE_DATA" = true ]; then echo "Running init_gages because --load-gages was specified." run_init_gages_and_store ""