Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions proxy/nginx.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/sh
set -eu

SUBST_VARS=$(grep -o '\${[A-Z_0-9]*}' /opt/nginx/nginx.conf.template | sort -u | tr '\n' ' ')
NGINX_CONFIG=/opt/nginx/nginx.conf
if [ -z "${OMEGA_AUTH_SECRET:-}" ] && [ -n "${OMEGACLAW_AUTH_SECRET:-}" ]; then
echo "OMEGACLAW_AUTH_SECRET is deprecated, rename it to OMEGA_AUTH_SECRET" >&2
OMEGA_AUTH_SECRET=${OMEGACLAW_AUTH_SECRET}
export OMEGA_AUTH_SECRET
fi

NGINX_TEMPLATE=${NGINX_TEMPLATE:-/opt/nginx/nginx.conf.template}
NGINX_CONFIG=${NGINX_CONFIG:-/opt/nginx/nginx.conf}
SUBST_VARS=$(grep -o '\${[A-Z_0-9]*}' "${NGINX_TEMPLATE}" | sort -u | tr '\n' ' ')
touch "${NGINX_CONFIG}"
chmod 0600 "${NGINX_CONFIG}"
envsubst "$SUBST_VARS" \
< /opt/nginx/nginx.conf.template \
< "${NGINX_TEMPLATE}" \
> "${NGINX_CONFIG}"

nginx -c "${NGINX_CONFIG}"
Expand Down
78 changes: 78 additions & 0 deletions scripts/omega
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,82 @@ options() {
fi
}

migrate_omegaclaw_memory() {
local old_container="omegaclaw"
local old_volume="omegaclaw-memory"
local new_volume="omega-memory"
local memory_path="/PeTTa/repos/Omega/memory"
local marker=".migrated-to-omega"
local started_marker=".migration-started"
local stopped_old_container=0
local old_state

if [ -n "${memory_import_file}" ] \
|| ! docker volume inspect "${old_volume}" >/dev/null 2>&1; then
return 0
fi
if ! old_state=$(docker run --rm --entrypoint sh --volume "${old_volume}:/from:ro" "${image}" \
-c "if [ -e /from/${marker} ]; then echo migrated; elif [ -e /from/${started_marker} ]; then echo interrupted; fi"); then
echo "Could not read the migration markers in ${old_volume}" >&2
return 1
fi
case "${old_state}" in
migrated)
return 0
;;
interrupted)
echo "The last copy from ${old_volume} did not finish, copying again"
if docker volume inspect "${new_volume}" >/dev/null 2>&1 \
&& ! docker volume rm "${new_volume}" >/dev/null; then
echo "Could not remove the partly copied volume ${new_volume}" >&2
return 1
fi
;;
*)
if docker volume inspect "${new_volume}" >/dev/null 2>&1; then
return 0
fi
;;
esac

echo "Copying memory from volume ${old_volume} to ${new_volume}"
if [ "$(docker inspect -f '{{.State.Running}}' "${old_container}" 2>/dev/null)" = "true" ]; then
if ! docker stop "${old_container}" >/dev/null; then
echo "Could not stop container ${old_container}, memory was not copied" >&2
return 1
fi
stopped_old_container=1
echo "Stopped container ${old_container}"
fi

if docker run --rm --entrypoint sh --volume "${old_volume}:/from" "${image}" \
-c "date -u > /from/${started_marker}" \
&& docker volume create "${new_volume}" >/dev/null \
&& docker run --rm --entrypoint sh --volume "${new_volume}:${memory_path}" "${image}" \
-c "test -f ${memory_path}/prompt.txt" \
&& docker run --rm --entrypoint sh \
--volume "${old_volume}:/from:ro" --volume "${new_volume}:/to" "${image}" \
-c 'list=$(mktemp) && cd /from && find . -mindepth 1 -maxdepth 1 ! -name "prompt*.txt" ! -name tg_prompt.txt ! -name .migration-started > "$list" && while IFS= read -r entry; do rm -rf "/to/$entry" && cp -a "$entry" /to/ || exit 1; done < "$list"' \
&& docker run --rm --entrypoint sh --volume "${old_volume}:/from" "${image}" \
-c "date -u > /from/${marker}"; then
echo "Memory copied. Carrying memory over is experimental, so keep the volume ${old_volume} until you have checked that the agent remembers what it knew. Then remove the old installation with 'docker rm ${old_container}' and 'docker volume rm ${old_volume}'"
return 0
fi

echo "Could not copy memory from ${old_volume}, the old installation is left as it was" >&2
if docker volume rm "${new_volume}" >/dev/null 2>&1 \
|| ! docker volume inspect "${new_volume}" >/dev/null 2>&1; then
docker run --rm --entrypoint sh --volume "${old_volume}:/from" "${image}" \
-c "rm -f /from/${started_marker}" >/dev/null 2>&1 || true
else
echo "Could not remove ${new_volume}, the next start will copy the memory again" >&2
fi
if [ "${stopped_old_container}" = "1" ]; then
docker start "${old_container}" >/dev/null 2>&1 || true
fi
return 1
}

prepare_memory_transfer_dir() {
python3 "$tmp_memory_transfer_validator" "${memory_transfer_dir}" "${memory_transfer_gid}"
}
Expand Down Expand Up @@ -911,6 +987,8 @@ start() {
fi
fi

migrate_omegaclaw_memory || return 1

docker rm -f omega 2>/dev/null || true

docker_cmd=(
Expand Down
Loading
Loading