From 01e776a5c3d6e4929e9fd7c65e6c328519040810 Mon Sep 17 00:00:00 2001 From: pennae Date: Wed, 27 Sep 2023 17:50:01 +0200 Subject: improve on-device logging slightly tell the user that a deployment has failed and log reboot messages from the device, just in case the network broke before the reboot (in which case logging the reboot event from the deploying host would be misleading) --- openwrt/config_generation.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'openwrt/config_generation.sh') diff --git a/openwrt/config_generation.sh b/openwrt/config_generation.sh index e119608..a442863 100644 --- a/openwrt/config_generation.sh +++ b/openwrt/config_generation.sh @@ -16,32 +16,37 @@ _rollback() { if mv -T /overlay/upper.prev /overlay/upper; then rm -rf /overlay/upper.dead else - echo "rollback failed, check /overlay/upper.dead and recover!" >&2 + echo "rollback failed, manual recovery needed. check /overlay/upper.dead!" >&2 exit 1 fi } apply() { CYAN='\e[36m' + RED='\e[31m' NORMAL='\e[0m' log() { printf "$CYAN>> %s$NORMAL\n" "$*" } + log_err() { + printf "$RED>> %s$NORMAL\n" "$*" + } + if ! rm -rf /overlay/upper.prev/ \ || ! cp -al /overlay/upper/ /overlay/upper.prev/ \ || ! rm -rf /overlay/upper.prev/etc/ \ || ! cp -a /overlay/upper/etc/ /overlay/upper.prev/ then - echo "failed to snapshot old config" + log_err "failed to snapshot old config" rm -rf /overlay/upper.prev exit 1 fi if ! /etc/init.d/config_generation enable then - echo "failed to schedule rollback" + log_err "failed to schedule rollback" rm -rf /overlay/upper.prev exit 1 fi @@ -57,8 +62,12 @@ apply() { @deploy_steps@ ) then + log_err 'deployment failed, rolling back and rebooting ...' _rollback + exit 1 fi + + log 'rebooting device ...' } commit() { -- cgit v1.2.3