The guard (SPEC 9.3, 9.4) is now the container's main process and the parent of the engine. It listens on a named pipe for the engine's heartbeat and startup steps, and steps in after two minutes of silence, ten minutes of a startup that does not move, or an exit without notice. It stops the engine, cancels our purchases and sales left open on demo accounts, puts back the stops the positions need from the state file the engine writes every ten seconds, writes a note, warns the user and restarts the engine without any injected fault. The third forced restart within an hour writes the STOP file. The container's stop is passed on to the engine, which closes in order. At restart the engine adopts the guard's stops before reconciling, cancels the orders it left open and plans again the exits already decided, so the rules of SPEC 5.6 apply to them. The acceptance test blocks the main loop right after a sale leaves: in process on a demo-like broker, and with real processes in the drill, which also runs inside the Docker image (tasks ci and the CI workflow). The guard uses the ASP.NET shared runtime so both programs share /app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.1 KiB
Bash
32 lines
1.1 KiB
Bash
#!/bin/sh
|
|
# Container start (SPEC 15.2, issue #16). As root: prepare /data for PUID:PGID (99:100 on Unraid), then drop to that
|
|
# user with setpriv, which is part of the base image (no gosu). Started as another user (docker run --user): go straight on.
|
|
# The process is the guard (SPEC 9.3, ADR 0012): it starts the engine, watches it and passes the stop on to it.
|
|
set -eu
|
|
|
|
app="/app/Anubis.Guard.dll"
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
exec dotnet "$app" "$@"
|
|
fi
|
|
|
|
uid="${PUID:-99}"
|
|
gid="${PGID:-100}"
|
|
case "$uid$gid" in
|
|
*[!0-9]*|"")
|
|
echo "PUID e PGID devono essere numeri (adesso: PUID=$uid PGID=$gid)." >&2
|
|
exit 64
|
|
;;
|
|
esac
|
|
|
|
mkdir -p /data
|
|
for folder in db models research import backups logs web-keys guard; do
|
|
mkdir -p "/data/$folder"
|
|
done
|
|
# Only what does not already belong to PUID:PGID, so a large data folder does not slow every start.
|
|
find /data -xdev \( ! -user "$uid" -o ! -group "$gid" \) -exec chown -h "$uid:$gid" {} +
|
|
chmod 700 /data
|
|
|
|
export HOME=/tmp
|
|
exec setpriv --reuid="$uid" --regid="$gid" --clear-groups -- dotnet "$app" "$@"
|