Public: anyone can read this; the crew can change it.

The game agent has one compose command: an array every call and the background job share #17261

opened this

Merged 35h 29m ago, live in production

sold/agent-compose-array → main 0 commits

  • Merged. sold/agent-compose-array was merged into main as c95f990.

Review

Sign in to review this change.
1 file changed +8 −7
src/games/agent.sh +8 −7
@@ -74,7 +74,9 @@ while [ -n "$(missing)" ]; do
7474 sleep "$MISSING_EVERY"
7575 done
7676 # The project directory is the box's own, so compose reads the `.env` the forge writes beside it.
77 compose() { "$DOCKER" compose -p game --project-directory "$DIR" -f "$DIR/compose.yml" "$@"; }
77 # One array, the real program and its flags: timeout(1) and `bash -c` both run it, which a shell
78 # function never could be.
79 COMPOSE=("$DOCKER" compose -p game --project-directory "$DIR" -f "$DIR/compose.yml")
7880 now() { date -u +%Y-%m-%dT%H:%M:%SZ; }
7981 # A quick command that must not hang the loop: at most 30 s where timeout(1) is there.
8082 # Run a command for at most `secs` seconds, timeout(1) or not: a docker that hangs never holds the
@@ -82,8 +84,7 @@ now() { date -u +%Y-%m-%dT%H:%M:%SZ; }
8284 capped() {
8385 local secs="$1" pid i
8486 shift
85 # timeout(1) runs a program, never a shell function (`compose` is one): a function takes the loop below.
86 if ! declare -F "$1" >/dev/null && command -v timeout >/dev/null 2>&1; then
87 if command -v timeout >/dev/null 2>&1; then
8788 timeout "$secs" "$@"
8889 return
8990 fi
@@ -113,7 +114,7 @@ since="$(now)"
113114 # The services as compose sees them, with each one's CPU and memory from docker stats.
114115 services() {
115116 local ps stats
116 ps="$(capped 5 compose ps -a --format json 2>/dev/null | jq -cs 'flatten' 2>/dev/null)" || ps='[]'
117 ps="$(capped 5 "${COMPOSE[@]}" ps -a --format json 2>/dev/null | jq -cs 'flatten' 2>/dev/null)" || ps='[]'
117118 [ -n "$ps" ] || ps='[]'
118119 stats="$(capped 5 "$DOCKER" stats --no-stream --format json 2>/dev/null | jq -cs '.' 2>/dev/null)" || stats='[]'
119120 [ -n "$stats" ] || stats='[]'
@@ -133,7 +134,7 @@ services() {
133134
134135 # New log lines since the last sync, at most 200 a service: "hub | text" split at the first bar.
135136 logs() {
136 capped 5 compose logs --no-color --since "$1" 2>/dev/null | jq -cRn '
137 capped 5 "${COMPOSE[@]}" logs --no-color --since "$1" 2>/dev/null | jq -cRn '
137138 [inputs | capture("^(?<s>[^ |]+)[ ]*\\| ?(?<l>.*)$")?]
138139 | group_by(.s) | map({key: .[0].s, value: (map(.l) | .[-200:])}) | from_entries' 2>/dev/null || echo '{}'
139140 }
@@ -161,7 +162,7 @@ run() {
161162 else
162163 case "$kind" in
163164 # Through compose, by service: a container is named game-<service>-1 unless the file says otherwise.
164 rcon) out="$(bounded30 compose exec -T "$service" rcon-cli -- "$text" 2>&1)" || ok=false ;;
165 rcon) out="$(bounded30 "${COMPOSE[@]}" exec -T "$service" rcon-cli -- "$text" 2>&1)" || ok=false ;;
165166 # Anything that can take long goes to the job queue: the sync never waits on it, and its
166167 # result is sent when it ends.
167168 restart | stop | start | pull)
@@ -250,7 +251,7 @@ job_tick() {
250251 now >"$DIR/.job.since"
251252 # Its own bash, named on its command line ($0), writing its exit status only when it ends.
252253 # shellcheck disable=SC2086,SC2016 # the verb and its words, each a safe name; the script is single-quoted on purpose
253 DOCKER="$DOCKER" DIR="$DIR" bash -c '"$DOCKER" compose -p game --project-directory "$DIR" -f "$DIR/compose.yml" "$@" >"$DIR/.up.log" 2>&1; echo $? >"$DIR/.job.rc"' "$JOB_MARK" $args &
254 DIR="$DIR" bash -c '"$@" >"$DIR/.up.log" 2>&1; echo $? >"$DIR/.job.rc"' "$JOB_MARK" "${COMPOSE[@]}" $args &
254255 echo $! >"$DIR/.job.pid"
255256 }
256257

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs