From 9e6e06fba9ae95d94a46e4006dd6ef05297bd4e4 Mon Sep 17 00:00:00 2001 From: Felix Kloss Date: Tue, 21 Jan 2025 12:04:41 +0100 Subject: [PATCH] Add basic monitoring with ntfy to container startscripts --- comprl-hockey-game/comprl-hockey.def | 12 +++++++++++- comprl-web-reflex/comprl-web-reflex.def | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/comprl-hockey-game/comprl-hockey.def b/comprl-hockey-game/comprl-hockey.def index 10a8cee..f821e6f 100644 --- a/comprl-hockey-game/comprl-hockey.def +++ b/comprl-hockey-game/comprl-hockey.def @@ -11,7 +11,7 @@ from: ubuntu:24.04 echo "deb http://archive.ubuntu.com/ubuntu noble universe" >> /etc/apt/sources.list apt-get update - apt-get install -y python3-dev python3-pip python3-full swig git + apt-get install -y curl python3-dev python3-pip python3-full swig git git clone https://github.com/martius-lab/teamproject-competition-server \ --depth 1 -b "{{ COMPRL_GIT_BRANCH }}" /comprl @@ -30,6 +30,7 @@ from: ubuntu:24.04 %environment export COMPRL_CONFIG_PATH="/comprl-config/config.toml" + export NTFY_TOPIC="comprl-server-monitor" %runscript @@ -38,10 +39,14 @@ from: ubuntu:24.04 %startscript + curl -d "Start comprl.server" ntfy.sh/${NTFY_TOPIC} + . /venv/bin/activate # assumes that the config is bound at that path python -m comprl.server --config "${COMPRL_CONFIG_PATH}" + curl -H "Priority: urgent" -H "Tags: warning" -d "comprl.server terminated. Exit code: $?" ntfy.sh/${NTFY_TOPIC} + %help Running the container with `instance start` will run the comprl server. @@ -58,10 +63,15 @@ from: ubuntu:24.04 export AGENT_TYPE=strong %appstart agent + curl -d "Start agent ${AGENT_TYPE}" ntfy.sh/${NTFY_TOPIC} + . /venv/bin/activate cd /comprl/comprl-hockey-agent python ./run_client.py --args --agent "${AGENT_TYPE}" + curl -H "Priority: urgent" -H "Tags: warning" -d "Agent terminated. Exit code: $?" ntfy.sh/${NTFY_TOPIC} + + %apphelp agent Run an example agent (using `apptainer instance start --app agent ...`). You need to provide the access token via the environment variable diff --git a/comprl-web-reflex/comprl-web-reflex.def b/comprl-web-reflex/comprl-web-reflex.def index c6aab43..cdc58d3 100644 --- a/comprl-web-reflex/comprl-web-reflex.def +++ b/comprl-web-reflex/comprl-web-reflex.def @@ -12,7 +12,7 @@ from: python:3.12 export DEBIAN_FRONTEND=noninteractive apt-get update - apt-get install -y git caddy redis-server + apt-get install -y git caddy redis-server curl git clone https://github.com/martius-lab/teamproject-competition-server --depth 1 -b "{{ COMPRL_GIT_BRANCH }}" /comprl @@ -49,9 +49,14 @@ from: python:3.12 %environment export REDIS_URL=redis://localhost export COMPRL_CONFIG_PATH="/comprl-config/config.toml" + export NTFY_TOPIC="comprl-server-monitor" %startscript + curl -d "Start comprl web interface" ntfy.sh/${NTFY_TOPIC} + . /venv/bin/activate redis-server --daemonize yes cd /comprl/comprl-web-reflex reflex run --env prod "$@" + + curl -H "Priority: urgent" -H "Tags: warning" -d "comprl web interface terminated. Exit code: $?" ntfy.sh/${NTFY_TOPIC}