puppet-tripleo/templates/neutron/neutron-keepalived-state-change.epp
Cédric Jeanneret f5a7ca6fb5 Correct how podman exec is called for the neutron-keepalived-state-change
Podman exec doesn't have the "--detach" flag, so this one didn't work at
all until now.

Change-Id: Ibf18056dc1ed0168b3aa467e7034af7e59c98cb7
2019-04-17 13:55:29 +02:00

48 lines
1.4 KiB
Plaintext

<%- | String $bind_socket = '',
Boolean $debug,
String $container_cli = ''
| -%>
#!/bin/bash
<%- if $debug { -%>set -x<%- } -%>
<%- if $bind_socket { -%>
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 ...
NETNS=$(ip netns identify)
NAME=neutron-keepalived-${NETNS}
<%- if $container_cli == 'docker' { -%>
CLI='docker exec --detach'
CMD="ip netns exec ${NETNS} /usr/bin/neutron-keepalived-state-change exec"
<%- } elsif $container_cli == 'podman' { -%>
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman exec"
CMD='/usr/bin/neutron-keepalived-state-change'
<%- } else { -%>
CLI='echo noop'
CMD='echo noop'
<%- } -%>
# 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=$($CLI ps --filter name=$NAME --format "{{.ID}}")
if [[ -z $container_id ]];
then
echo "WARNING: keepalived container is not running."
exit 0
fi
$CLI -u root \
--privileged \
$NAME \
$CMD $ARGS