From 9fd892a22413104b3a34554588468cd94d1a599e Mon Sep 17 00:00:00 2001 From: Matthias Stecher Date: Mon, 13 Jul 2020 20:31:18 +0200 Subject: [PATCH] [__lxc_container] add --restart-if-changed parameter to apply changes This parameter restarts the container if configuration changes and it is already running and should keept running. It handles the freeze state, because it would be expected to apply changes in this state, too. --- .../conf/type/__lxc_container/gencode-remote | 49 ++++++++++++++++++- cdist/conf/type/__lxc_container/man.rst | 6 ++- .../type/__lxc_container/parameter/boolean | 1 + 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__lxc_container/gencode-remote b/cdist/conf/type/__lxc_container/gencode-remote index ddba593a..480d7d41 100755 --- a/cdist/conf/type/__lxc_container/gencode-remote +++ b/cdist/conf/type/__lxc_container/gencode-remote @@ -234,8 +234,55 @@ DONE rm -rf "$container_config" mv "\$tmpconfig" "$container_config" DONE - # write message echo "config" >> "$__messages_out" + + + # restart container only if it is running + # do not echo messages start/stop or melt/start/stop/freeze; only restart to avoid junk + case "$state_is" in + running|frozen) + # only do it if the container will run again + case "$state_should" in + present|running|frozen) + # su stuff + cat <> "$__messages_out" + fi + fi + + # ending + echo "restart" >> "$__messages_out" + echo "SU" + ;; + esac + ;; + esac fi diff --git a/cdist/conf/type/__lxc_container/man.rst b/cdist/conf/type/__lxc_container/man.rst index d0abf2e2..7d1f6522 100644 --- a/cdist/conf/type/__lxc_container/man.rst +++ b/cdist/conf/type/__lxc_container/man.rst @@ -70,7 +70,11 @@ config-absent BOOLEAN PARAMETERS ------------------ -None. + +restart-if-changed + Restarts the container if configuration changes. It stop and start the container that new configuration + can be applied. If it whould be restarted with ``lxc-stop -n $name --reboot``, configuration changes + would be ignored. CREATE PARAMETERS ----------------- diff --git a/cdist/conf/type/__lxc_container/parameter/boolean b/cdist/conf/type/__lxc_container/parameter/boolean index caf89a8e..724fa14b 100644 --- a/cdist/conf/type/__lxc_container/parameter/boolean +++ b/cdist/conf/type/__lxc_container/parameter/boolean @@ -1 +1,2 @@ no-default-config +restart-if-changed