Script to improve handling for dynamic Minecraft server list

- Updates list of servers monitored by exporter-minecraft
- Updates router mappings
- Produces no stdout (potentially stderr)
- Idempotent (if no change is necessary, no change is made
This commit is contained in:
Joey Hafner 2022-11-01 15:23:03 -07:00
parent 306bd8d132
commit 3f1c337cad
2 changed files with 31 additions and 1 deletions

View File

@ -2,7 +2,7 @@ version: '3'
services:
router:
image: itzg/mc-router
container_name: minecraft_mc-router
container_name: minecraft_router
logging:
driver: loki
options:

View File

@ -0,0 +1,30 @@
#!/bin/bash
# Get list of configured servers
# One server per line, includes router
SERVERS="$(docker-compose -f ~/homelab/server/config/minecraft/docker-compose.yml config --services)"
# exporter-minecraft: Create comma-separated list for EXPORT_SERVERS
EXPORT_SERVERS=""
for server in $SERVERS
do
if [ $server != "router" ]
then EXPORT_SERVERS="${EXPORT_SERVERS}${EXPORT_SERVERS:+,}$server"
fi
done
echo "EXPORT_SERVERS=\"$EXPORT_SERVERS\"" > /home/joey/homelab/server/config/monitoring/exporter-minecraft.yml
# router: Create valid and correct mapping command for mc-router
# example: command: --mapping=vanilla.jafner.net=vanilla:25565,e9.jafner.net=e9:25565,fan.jafner.net=fan:25565,vanilla2.jafner.net=vanilla2:25565,bmcp.jafner.net=bmcp:25565 --api-binding=0.0.0.0:25566
MAPPINGS=""
for server in $SERVERS
do
#MAPPING="$server.jafner.net=$server:25565"
#echo $MAPPING
if [ $server != "router" ]
then MAPPINGS="${MAPPINGS}${MAPPINGS:+,}$server.janfer.net=$server:25565"
fi
done
#COMMAND="command: --mapping=$MAPPINGS --api-binding=0.0.0.0:25566"
sed -i "s/--mapping=[^ ]\+/--mapping=$MAPPINGS/m" /home/joey/homelab/server/config/minecraft/docker-compose.yml