Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing the effects of releasing the dhcp lease when a container is destroyed
#!/bin/bash
#
# test-dnsmasq
#
app="wordpress"
container="${app}-container"
domain="${app}.local.lxc"
LEASES="/var/lib/misc/dnsmasq.leases"
release_lease() {
local name=$1
# release dnsmasq lease, if any before creating new container
container_mac=$(grep "\s${name}\s" ${LEASES} | awk '{print $2}')
container_ip=$( grep "\s${name}\s" ${LEASES} | awk '{print $3}')
dhcp_release natbr0 ${container_ip} ${container_mac}
}
wait_for_host() {
# wait for host name resolution
# it does not mean that host is up
local hostname="$1"
local retries="${2:-10}"
local delay="${3:-3}"
for (( i=1; i<=${retries}; i++ )); do
host ${hostname} > /dev/null && return 0;
sleep ${delay}
done
return 1;
}
# main
echo "Starting Test: $(host ${container})"
lxc-create -q -n ${container} -t turnkey -- ${app} -i ~/inithooks.conf
echo "Container created: $(host ${container})"
lxc-start -d -n ${container}
wait_for_host ${container}
echo "Container started: $(host ${container})"
nginx-proxy -d ${app}.local.lxc -n ${container}
echo "Proxy Created: $(host ${container})"
lxc-stop -n ${container}
echo "Container stopped: $(host ${container})"
lxc-destroy -n ${container}
echo "Container destroyed: $(host ${container})"
release_lease ${container}
echo "dnsmasq lease released: $(host ${container})"
echo "Reloading nginx:"
service nginx reload
echo "Display nginx status:"
systemctl status nginx.service -l
journalctl -xn
nginx-proxy --remove -d ${app}.local.lxc -n ${container}
echo "Proxy Removed: $(host ${container})"
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment