33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
<%- | String $ns_prefix = '', String $bind_socket = '' | -%>
|
|
#!/bin/bash
|
|
|
|
export DOCKER_HOST="<%=$bind_socket%>"
|
|
ARGS="$@"
|
|
|
|
# Extract the network namespace UUID from the command line args provided by
|
|
# neutron. Typically of the form (with dnsmasq as an example):
|
|
#
|
|
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
|
|
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
|
|
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
|
|
NS_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
|
|
NAME=neutron-keepalived-<%=$ns_prefix%>-${NS_ID}
|
|
|
|
# The state change daemon only runs as a daemon for the moment so we need to
|
|
# run it within an existing container with a sensibly matching lifetime. The
|
|
# related keepalived container seems an obvious choice.
|
|
|
|
container_id=`docker ps --filter name=$NAME --format "{{.ID}}"`
|
|
|
|
if [[ -z $container_id ]];
|
|
then
|
|
echo "WARNING: keepalived container is not running."
|
|
exit 0
|
|
fi
|
|
|
|
docker exec --detach \
|
|
-u root \
|
|
--privileged \
|
|
$NAME \
|
|
ip netns exec <%=$ns_prefix%>-${NS_ID} /usr/bin/neutron-keepalived-state-change $ARGS
|