[fix] Add conditions for commands so they're less likely to fail

This commit is contained in:
William Wernert
2020-11-04 14:20:26 -05:00
parent b2759c4c7c
commit 1e41b9ba31

View File

@@ -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"
{
# Remove startup_states from minion config so we don't immediately highstate when salt starts back up
sed -i '/startup_states/d' $minion_config
local minion_config=/etc/salt/minion
# Remove startup_states from minion config so we don't immediately highstate when salt starts back up
if [[ -f $minion_config ]] && grep -q "startup_states" $minion_config; then
sed -i '/startup_states/d' $minion_config
fi
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
fi
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