AutoDevReverseProxy/script/hostman.sh

42 lines
1.2 KiB
Bash
Raw Normal View History

2022-11-04 13:01:36 +01:00
#!/usr/bin/env sh
2022-11-04 13:01:36 +01:00
# Configurable Variables
DOCKER_SOCK_PATH="${DOCKER_SOCK_PATH:-/tmp/docker.sock}"
NETWORK_NAME="${NETWORK_NAME:-proxy}"
TEMPLATER_PATH="${TEMPLATER_PATH:-/docker-templater.sh}"
TEMPLATE_FOLDER_PATH="${TEMPLATE_FOLDER_PATH:-/templates}"
2022-11-04 13:01:36 +01:00
query_docker () {
2022-11-17 14:51:49 +01:00
curl --unix-socket $DOCKER_SOCK_PATH --silent -g http://v1.41/$1$2
2022-11-04 13:01:36 +01:00
}
update_templates() {
CONTAINER_LIST=$(query_docker "containers/json" "?filters={%22network%22:[%22${NETWORK_NAME}%22],%22status%22:[%22running%22]}")
if [ "${CONTAINER_LIST}" != "${OLD_CONTAINER_LIST}" ]
then
for template in "${TEMPLATE_FOLDER_PATH}"/*
2022-11-04 13:01:36 +01:00
do
if ! "${TEMPLATER_PATH}" "${template}" "${CONTAINER_LIST}"
then
echo "Error Processing Template: ${template}"
fi
2022-11-04 13:01:36 +01:00
done
OLD_CONTAINER_LIST="${CONTAINER_LIST}"
fi
2022-11-11 15:39:33 +01:00
}
2022-11-04 13:01:36 +01:00
# Initial Generation
update_templates
2022-11-17 14:51:49 +01:00
# cannot filter because reailine no longer recognized lines otherwise (check how IFS changes)
query_docker "events" | while true
do
read -r;
# wait for related events to finish
while [ $? -eq 0 ]
do
read -t 8 -r
2022-11-17 14:51:49 +01:00
done
update_templates
2022-11-04 13:01:36 +01:00
done