[__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.
This commit is contained in:
matze 2020-07-13 20:31:18 +02:00
commit 9fd892a224
3 changed files with 54 additions and 2 deletions

View file

@ -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 <<USER
su "$user" - <<SU
USER
# unfreeze if required
if [ "$state_is" = "frozen" ]; then
cat <<LXC
lxc-unfreeze $LXC_PARAM -n "$name"
LXC
fi
# stop and start
cat <<LXC
lxc-stop $LXC_PARAM -n "$name"
lxc-start $LXC_PARAM -n "$name"
LXC
# freeze it again if it was there before, but be clever
# if $state_is = running but should be frozen, later code will do that
if [ "$state_is" = "frozen" ]; then
if [ "$state_should" = "frozen" ] || [ "$state_should" = "present" ]; then
cat <<LXC
lxc-freeze $LXC_PARAM -n "$name"
LXC
else
# correct current state
state_is="running"
echo "melt" >> "$__messages_out"
fi
fi
# ending
echo "restart" >> "$__messages_out"
echo "SU"
;;
esac
;;
esac
fi

View file

@ -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
-----------------

View file

@ -1 +1,2 @@
no-default-config
restart-if-changed