Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-04 08:56:31

0001 #!/bin/bash
0002 set -e
0003 
0004 # ---- Environment variables required by agents.supervisord.conf ----
0005 # %(ENV_SWF_HOME)s/swf-testbed  →  /opt/swf-testbed  →  /app  (via symlink)
0006 export SWF_HOME=/opt
0007 # %(ENV_USER)s — used for the supervisord socket path
0008 export USER=${USER:-root}
0009 # %(ENV_SWF_TESTBED_CONFIG)s — config path passed to agents
0010 export SWF_TESTBED_CONFIG=${SWF_TESTBED_CONFIG:-workflows/testbed.toml}
0011 # Skip venv activation in workflow_runner.py and agent scripts
0012 export VIRTUAL_ENV=${VIRTUAL_ENV:-/usr/local}
0013 
0014 # PostgreSQL and ActiveMQ readiness is guaranteed by docker-compose healthchecks
0015 # (depends_on with condition: service_healthy), so no wait loops needed here.
0016 
0017 echo "==> Generating API token for agents …"
0018 # get_token outputs: '... token for user "admin": <hex>'  — extract the 40-char hex token
0019 SWF_API_TOKEN=$(python /opt/swf-monitor/src/manage.py get_token admin 2>/dev/null | grep -oP '[0-9a-f]{40}')
0020 export SWF_API_TOKEN
0021 echo "==> API token ready"
0022 
0023 echo "==> Starting: $@"
0024 "$@"
0025 CMD_EXIT=$?
0026 
0027 if [ $CMD_EXIT -ne 0 ]; then
0028     echo "==> Command failed with exit code $CMD_EXIT"
0029     exit $CMD_EXIT
0030 fi
0031 
0032 # Keep the container alive so supervisord-managed agents can keep running.
0033 # testbed run triggers the workflow and exits, but the agents (workflow-runner,
0034 # processing-agent, etc.) are background processes under supervisord.
0035 AGENTS_PID_FILE=/app/agents-supervisord.pid
0036 if [ -f "$AGENTS_PID_FILE" ]; then
0037     SUPD_PID=$(cat "$AGENTS_PID_FILE")
0038     echo "==> Agents running under supervisord (pid $SUPD_PID). Tailing logs …"
0039     # Forward SIGTERM/SIGINT to supervisord so 'docker stop' shuts down cleanly
0040     trap "echo '==> Shutting down supervisord …'; kill -TERM $SUPD_PID; wait $SUPD_PID 2>/dev/null; exit 0" TERM INT
0041     # Tail agent logs to keep the container alive and stream output
0042     tail -F /app/logs/*.log 2>/dev/null &
0043     TAIL_PID=$!
0044     # Wait until supervisord exits
0045     while kill -0 "$SUPD_PID" 2>/dev/null; do
0046         sleep 2
0047     done
0048     kill $TAIL_PID 2>/dev/null
0049     echo "==> Supervisord exited."
0050 else
0051     echo "==> No supervisord pid file found. Exiting."
0052 fi