From 1e41b9ba3102cfa51175e920b414b64a2f922e5a Mon Sep 17 00:00:00 2001 From: William Wernert Date: Wed, 4 Nov 2020 14:20:26 -0500 Subject: [PATCH] [fix] Add conditions for commands so they're less likely to fail --- setup/so-functions | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/setup/so-functions b/setup/so-functions index 0291c5641..faadee63f 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1410,27 +1410,37 @@ reserve_group_ids() { } reinstall_init() { - local minion_config=/etc/salt/minion - info "Putting system in state to run setup again" - info "Some commands may fail depending on whether setup previously succeeded" { + local minion_config=/etc/salt/minion + # Remove startup_states from minion config so we don't immediately highstate when salt starts back up - sed -i '/startup_states/d' $minion_config + if [[ -f $minion_config ]] && grep -q "startup_states" $minion_config; then + sed -i '/startup_states/d' $minion_config + fi - # Disable schedule so highstate doesn't start running during the install - salt-call -l info schedule.disable + if command -v salt-call &> /dev/null; then + # Disable schedule so highstate doesn't start running during the install + salt-call -l info schedule.disable - # Kill any currently running salt jobs, also to prevent issues with highstate. - salt-call -l info saltutil.kill_all_jobs + # Kill any currently running salt jobs, also to prevent issues with highstate. + salt-call -l info saltutil.kill_all_jobs + fi - # Stop and remove all so-* containers so files can be changed with more safety - docker stop $(docker ps -a -q --filter "name=so-") - docker rm -f $(docker ps -a -q --filter "name=so-") + if command -v docker &> /dev/null; then + # Stop and remove all so-* containers so files can be changed with more safety + docker stop $(docker ps -a -q --filter "name=so-") + docker rm -f $(docker ps -a -q --filter "name=so-") + fi + + local date_string + date_string=$(date +%s) # Backup /opt/so since we'll be rebuilding this directory during setup - mv /opt/so "/opt/so_old_$(date +%s)" + if [[ -d /opt/so ]]; then + mv /opt/so "/opt/so_old_${date_string}" + fi # Remove container data directories rm -rf /nsm/mysql