Spaces:
Running
Running
Upload start.sh
Browse files- scripts/start.sh +9 -11
scripts/start.sh
CHANGED
|
@@ -11,19 +11,16 @@ if [ ! -d /data ]; then
|
|
| 11 |
data_root="/app/es-data"
|
| 12 |
fi
|
| 13 |
export DATA_ROOT="${DATA_ROOT:-${app_data_root}}"
|
| 14 |
-
|
|
|
|
| 15 |
if [ -n "${bucket_dir}" ]; then
|
| 16 |
-
mkdir -p "${bucket_dir}/
|
| 17 |
-
# Elasticsearch runs as its own user and must create repository verification blobs.
|
| 18 |
-
if ! chown elasticsearch:elasticsearch "${bucket_dir}/snapshots" "${bucket_dir}/snapshots/probe" "${bucket_dir}/snapshots/production"; then
|
| 19 |
-
chmod 0777 "${bucket_dir}/snapshots" "${bucket_dir}/snapshots/probe" "${bucket_dir}/snapshots/production"
|
| 20 |
-
fi
|
| 21 |
fi
|
| 22 |
index_version="$(python -c 'from app.config import INDEX_VERSION; print(INDEX_VERSION)')"
|
| 23 |
version_file="${DATA_ROOT}/es-index-version"
|
| 24 |
status_file="${DATA_ROOT}/index-status"
|
| 25 |
|
| 26 |
-
chown -R elasticsearch:elasticsearch "${data_root}" /app/logs
|
| 27 |
cat > "${ES_HOME}/config/elasticsearch.yml" <<EOF
|
| 28 |
cluster.name: bha-lite
|
| 29 |
node.name: bha-lite-node
|
|
@@ -34,22 +31,21 @@ xpack.security.enabled: false
|
|
| 34 |
xpack.security.http.ssl.enabled: false
|
| 35 |
path.data: ${data_root}
|
| 36 |
path.logs: /app/logs
|
|
|
|
| 37 |
EOF
|
| 38 |
-
if [ -n "${bucket_dir}" ]; then
|
| 39 |
-
printf 'path.repo: %s\n' "${bucket_dir}/snapshots" >> "${ES_HOME}/config/elasticsearch.yml"
|
| 40 |
-
fi
|
| 41 |
chown elasticsearch:elasticsearch "${ES_HOME}/config/elasticsearch.yml"
|
| 42 |
uvicorn app.main:app --host 0.0.0.0 --port "${PORT}" &
|
| 43 |
api_pid="$!"
|
| 44 |
su -s /bin/bash elasticsearch -c "${ES_HOME}/bin/elasticsearch" &
|
| 45 |
es_pid="$!"
|
| 46 |
(
|
|
|
|
| 47 |
/app/scripts/wait-for-es.sh
|
| 48 |
if [ "${BHA_BUCKET_PROBE:-0}" = "1" ]; then
|
| 49 |
python -m app.bucket_probe "${bucket_dir}"
|
| 50 |
exit $?
|
| 51 |
fi
|
| 52 |
-
if [ -n "${bucket_dir}" ]; then
|
| 53 |
printf 'restoring' > "${status_file}"
|
| 54 |
if python -m app.bucket_snapshot restore "${bucket_dir}"; then
|
| 55 |
printf '%s' "${index_version}" > "${version_file}"
|
|
@@ -69,6 +65,8 @@ es_pid="$!"
|
|
| 69 |
fi
|
| 70 |
else
|
| 71 |
printf 'failed' > "${status_file}"
|
|
|
|
|
|
|
| 72 |
fi
|
| 73 |
) &
|
| 74 |
indexer_pid="$!"
|
|
|
|
| 11 |
data_root="/app/es-data"
|
| 12 |
fi
|
| 13 |
export DATA_ROOT="${DATA_ROOT:-${app_data_root}}"
|
| 14 |
+
snapshot_repo_root="${DATA_ROOT}/es-repositories"
|
| 15 |
+
mkdir -p "${data_root}" /app/logs "${DATA_ROOT}" "${snapshot_repo_root}/production" "${snapshot_repo_root}/probe"
|
| 16 |
if [ -n "${bucket_dir}" ]; then
|
| 17 |
+
mkdir -p "${bucket_dir}/generations"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
fi
|
| 19 |
index_version="$(python -c 'from app.config import INDEX_VERSION; print(INDEX_VERSION)')"
|
| 20 |
version_file="${DATA_ROOT}/es-index-version"
|
| 21 |
status_file="${DATA_ROOT}/index-status"
|
| 22 |
|
| 23 |
+
chown -R elasticsearch:elasticsearch "${data_root}" /app/logs "${snapshot_repo_root}"
|
| 24 |
cat > "${ES_HOME}/config/elasticsearch.yml" <<EOF
|
| 25 |
cluster.name: bha-lite
|
| 26 |
node.name: bha-lite-node
|
|
|
|
| 31 |
xpack.security.http.ssl.enabled: false
|
| 32 |
path.data: ${data_root}
|
| 33 |
path.logs: /app/logs
|
| 34 |
+
path.repo: ${snapshot_repo_root}
|
| 35 |
EOF
|
|
|
|
|
|
|
|
|
|
| 36 |
chown elasticsearch:elasticsearch "${ES_HOME}/config/elasticsearch.yml"
|
| 37 |
uvicorn app.main:app --host 0.0.0.0 --port "${PORT}" &
|
| 38 |
api_pid="$!"
|
| 39 |
su -s /bin/bash elasticsearch -c "${ES_HOME}/bin/elasticsearch" &
|
| 40 |
es_pid="$!"
|
| 41 |
(
|
| 42 |
+
trap 'rc=$?; printf "failed" > "${status_file}"; kill "${api_pid}" "${es_pid}" 2>/dev/null || true; exit "${rc}"' ERR
|
| 43 |
/app/scripts/wait-for-es.sh
|
| 44 |
if [ "${BHA_BUCKET_PROBE:-0}" = "1" ]; then
|
| 45 |
python -m app.bucket_probe "${bucket_dir}"
|
| 46 |
exit $?
|
| 47 |
fi
|
| 48 |
+
if [ -n "${bucket_dir}" ] && [ "${RESET_INDEX:-0}" != "1" ]; then
|
| 49 |
printf 'restoring' > "${status_file}"
|
| 50 |
if python -m app.bucket_snapshot restore "${bucket_dir}"; then
|
| 51 |
printf '%s' "${index_version}" > "${version_file}"
|
|
|
|
| 65 |
fi
|
| 66 |
else
|
| 67 |
printf 'failed' > "${status_file}"
|
| 68 |
+
kill "${api_pid}" "${es_pid}" 2>/dev/null || true
|
| 69 |
+
exit 1
|
| 70 |
fi
|
| 71 |
) &
|
| 72 |
indexer_pid="$!"
|