From a372183af9d397154786e93bf87e7260798c4ea7 Mon Sep 17 00:00:00 2001
From: Kevin Carter <kevin.carter@rackspace.com>
Date: Sat, 17 Mar 2018 01:19:39 -0500
Subject: [PATCH] Add lxc.haltsignal to container configs

This change adds the lxc.haltsignal option to the container config which
ensures containers are gracefully stopped but quickly.

Presently, when a container is restart they can hang for 20 - 30 seconds
which is due to the fact that the default stop signal is SIGPWR.
While the hang when stopping a container is not 100% reproducible in all
environments it can be seen when simply executing `lxc-stop`. If the
user were to stream the container journal while stopping the container
it's would be seen that the container hangs when trying to shutdown some
systemd services. If the `lxc-stop` command is executed a second time the
container is stopped more forcibly with SIGRTMIN+3. This change is using
an example stop signal from the lxc documentation [0] which is
implementing a Real-time signal, SIGRTMIN+n. More on the signal used can
be found here [1].

[0] http://manpages.ubuntu.com/manpages/xenial/en/man5/lxc.container.conf.5.html
[1] http://manpages.ubuntu.com/manpages/xenial/en/man7/signal.7.html

Change-Id: I01e82eabf17d2ac5a89c13ef56616fd1fe0607dd
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
---
 tasks/lxc_container_config.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tasks/lxc_container_config.yml b/tasks/lxc_container_config.yml
index 0c94c3c..04b5de9 100644
--- a/tasks/lxc_container_config.yml
+++ b/tasks/lxc_container_config.yml
@@ -165,8 +165,7 @@
     mode: "0755"
   delegate_to: "{{ physical_host }}"
 
-# This is being defined due to an issue with dangling veth pairs.
-- name: Defines a pre and post hook script
+- name: Defines a pre, post, and haltsignal configs
   lineinfile:
     dest: "/var/lib/lxc/{{ inventory_hostname }}/config"
     line: "{{ item }}"
@@ -174,6 +173,7 @@
   with_items:
     - "lxc.hook.pre-start = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
     - "lxc.hook.post-stop = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
+    - "lxc.haltsignal = SIGRTMIN+4"
   delegate_to: "{{ physical_host }}"
 
 - name: Run veth wiring