From 61e20312ff66ab8d9af6ed2963ffc3acca50b14e Mon Sep 17 00:00:00 2001 From: pennae Date: Thu, 28 Sep 2023 02:14:29 +0200 Subject: add reload-only deployment option this is mostly useful for things like static dhcp lease tables. reboots may be a bit harsh for those. --- openwrt/config_generation.sh | 50 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'openwrt/config_generation.sh') diff --git a/openwrt/config_generation.sh b/openwrt/config_generation.sh index 8c3dde0..f4b25c5 100644 --- a/openwrt/config_generation.sh +++ b/openwrt/config_generation.sh @@ -1,6 +1,6 @@ #!/bin/sh /etc/rc.common -EXTRA_COMMANDS="apply commit" +EXTRA_COMMANDS="apply_reboot prepare_reload apply_reload commit" START=99 _unregister_script() { @@ -21,7 +21,7 @@ _rollback() { fi } -apply() { +_prepare_apply() { CYAN='\e[36m' RED='\e[31m' NORMAL='\e[0m' @@ -55,18 +55,24 @@ apply() { rm -rf /overlay/upper.prev exit 1 fi +} + +_run_steps() { + ( + set -e + @deploy_steps@ + ) +} + +apply_reboot() { + _prepare_apply # everything after this point may fail. if it does we'll simply roll back # immediately and reboot. trap 'reboot &' EXIT - if ! ( - set -e - - @deploy_steps@ - ) - then + if ! _run_steps; then log_err 'deployment failed, rolling back and rebooting ...' _rollback exit 1 @@ -75,6 +81,34 @@ apply() { log 'rebooting device ...' } +prepare_reload() { + mkdir /overlay/upper.prev + /etc/init.d/config_generation enable +} + +apply_reload() { + _prepare_apply + + # everything after this point may fail. if it does we'll simply roll back + # immediately and reboot. + + trap 'reboot &' EXIT + + if _run_steps; then + trap '' EXIT + log 'reloading config ...' + reload_config + # give service restarts a chance + log 'waiting @reload_service_wait@s for services ...' + sleep @reload_service_wait@ + exit 0 + else + log_err 'deployment failed, rolling back and rebooting ...' + _rollback + exit 1 + fi +} + commit() { if ! [ -e /overlay/upper.prev ]; then exit 1 -- cgit v1.2.3