diff options
author | pennae <pennae.git@eno.space> | 2023-09-28 02:14:29 +0200 |
---|---|---|
committer | pennae <pennae.git@eno.space> | 2023-09-28 02:46:04 +0200 |
commit | 61e20312ff66ab8d9af6ed2963ffc3acca50b14e (patch) | |
tree | ed23d9bf968bb36cd2d5b4a215bbfc22fa2682f2 /openwrt/config_generation.sh | |
parent | c7816b1fb3f0dcb16201976876d200202a1b41ff (diff) | |
download | dewclaw-61e20312ff66ab8d9af6ed2963ffc3acca50b14e.tar.gz dewclaw-61e20312ff66ab8d9af6ed2963ffc3acca50b14e.tar.xz dewclaw-61e20312ff66ab8d9af6ed2963ffc3acca50b14e.zip |
add reload-only deployment option
this is mostly useful for things like static dhcp lease tables. reboots
may be a bit harsh for those.
Diffstat (limited to 'openwrt/config_generation.sh')
-rw-r--r-- | openwrt/config_generation.sh | 50 |
1 files changed, 42 insertions, 8 deletions
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 |