From 0e580c9caf8606e2559b369eb9654fdad0fc05dc Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 19 Jun 2018 15:37:28 -0700 Subject: [PATCH 1/2] Manually send SIGHUP to vtysh when the current session was disconnected --- dockers/docker-fpm-frr/base_image_files/vtysh | 16 +++++++++++++++- dockers/docker-fpm-quagga/base_image_files/vtysh | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dockers/docker-fpm-frr/base_image_files/vtysh b/dockers/docker-fpm-frr/base_image_files/vtysh index c479fcd3653..573d121ddfa 100755 --- a/dockers/docker-fpm-frr/base_image_files/vtysh +++ b/dockers/docker-fpm-frr/base_image_files/vtysh @@ -1,3 +1,17 @@ #!/bin/bash -docker exec -i bgp vtysh "$@" +# Determine whether stdout is on a terminal +if [ -t 1 ] ; then + # Prepare a function to send HUP signal to vtysh in the container + # we mark the new instance of vtysh with current tty as a tag + TTY=$(tty) + function cleanup + { + PID_FOR_HUP=$(docker exec -i bgp ps a | grep "vtysh $TTY" | awk '{print $1; }') + docker exec -i bgp kill -HUP $PID_FOR_HUP + } + trap cleanup HUP + docker exec -ti bgp vtysh "$TTY" "$@" +else + docker exec -i bgp vtysh "$@" +fi diff --git a/dockers/docker-fpm-quagga/base_image_files/vtysh b/dockers/docker-fpm-quagga/base_image_files/vtysh index c479fcd3653..573d121ddfa 100755 --- a/dockers/docker-fpm-quagga/base_image_files/vtysh +++ b/dockers/docker-fpm-quagga/base_image_files/vtysh @@ -1,3 +1,17 @@ #!/bin/bash -docker exec -i bgp vtysh "$@" +# Determine whether stdout is on a terminal +if [ -t 1 ] ; then + # Prepare a function to send HUP signal to vtysh in the container + # we mark the new instance of vtysh with current tty as a tag + TTY=$(tty) + function cleanup + { + PID_FOR_HUP=$(docker exec -i bgp ps a | grep "vtysh $TTY" | awk '{print $1; }') + docker exec -i bgp kill -HUP $PID_FOR_HUP + } + trap cleanup HUP + docker exec -ti bgp vtysh "$TTY" "$@" +else + docker exec -i bgp vtysh "$@" +fi From 0e251f91f98b43fed7cf9057f34fd3ef833f8aa0 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 19 Jun 2018 16:16:57 -0700 Subject: [PATCH 2/2] Address comments --- dockers/docker-fpm-frr/base_image_files/vtysh | 5 ++--- dockers/docker-fpm-quagga/base_image_files/vtysh | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dockers/docker-fpm-frr/base_image_files/vtysh b/dockers/docker-fpm-frr/base_image_files/vtysh index 573d121ddfa..24016bd96b2 100755 --- a/dockers/docker-fpm-frr/base_image_files/vtysh +++ b/dockers/docker-fpm-frr/base_image_files/vtysh @@ -3,12 +3,11 @@ # Determine whether stdout is on a terminal if [ -t 1 ] ; then # Prepare a function to send HUP signal to vtysh in the container - # we mark the new instance of vtysh with current tty as a tag + # we mark the new instance of vtysh with the current tty as a tag TTY=$(tty) function cleanup { - PID_FOR_HUP=$(docker exec -i bgp ps a | grep "vtysh $TTY" | awk '{print $1; }') - docker exec -i bgp kill -HUP $PID_FOR_HUP + docker exec -i bgp pkill -HUP -f "vtysh $TTY" } trap cleanup HUP docker exec -ti bgp vtysh "$TTY" "$@" diff --git a/dockers/docker-fpm-quagga/base_image_files/vtysh b/dockers/docker-fpm-quagga/base_image_files/vtysh index 573d121ddfa..24016bd96b2 100755 --- a/dockers/docker-fpm-quagga/base_image_files/vtysh +++ b/dockers/docker-fpm-quagga/base_image_files/vtysh @@ -3,12 +3,11 @@ # Determine whether stdout is on a terminal if [ -t 1 ] ; then # Prepare a function to send HUP signal to vtysh in the container - # we mark the new instance of vtysh with current tty as a tag + # we mark the new instance of vtysh with the current tty as a tag TTY=$(tty) function cleanup { - PID_FOR_HUP=$(docker exec -i bgp ps a | grep "vtysh $TTY" | awk '{print $1; }') - docker exec -i bgp kill -HUP $PID_FOR_HUP + docker exec -i bgp pkill -HUP -f "vtysh $TTY" } trap cleanup HUP docker exec -ti bgp vtysh "$TTY" "$@"