From 38028a543a92f6e88bba7221c6149b702ea45fb5 Mon Sep 17 00:00:00 2001 From: William Wernert Date: Tue, 1 Dec 2020 21:18:24 -0500 Subject: [PATCH] [feat] Add timeout for salt services to stop during reinstall init --- setup/so-functions | 25 ++++++++++++++++++++++++- setup/so-whiptail | 13 +++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/setup/so-functions b/setup/so-functions index b3986c826..8c06888f6 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1382,6 +1382,12 @@ reserve_group_ids() { reinstall_init() { info "Putting system in state to run setup again" + + local salt_services=( + "salt-master" + "salt-minion" + ) + local service_retry_count=20 { # Disable all scheduled jobs @@ -1390,7 +1396,24 @@ reinstall_init() { fi # Kill any salt processes (safely) - systemctl stop salt-* + for service in "${salt_services[@]}"; do + # Stop the service in the background so we can exit after a certain amount of time + systemctl stop "$service" & + local pid=$! + + local count=0 + while ! (check_service_status "$service"); do + if [ count > $service_retry_count ]; then + echo "Could not stop $service after 1 minute, exiting setup." + + # Stop the systemctl process trying to kill the service, show user a message, then exit setup + kill -9 $pid + whiptail_service_stop_failed "$service" + fi + sleep 5 + ((count++)) + done + done # Remove all salt configs rm -rf /etc/salt/global /etc/salt/minion /etc/salt/master /etc/salt/pki/* diff --git a/setup/so-whiptail b/setup/so-whiptail index 11d968910..a41e61f94 100755 --- a/setup/so-whiptail +++ b/setup/so-whiptail @@ -1175,6 +1175,19 @@ whiptail_sensor_config() { } +whiptail_service_stop_failed() { + local service=$1 + + read -r -d '' message <<- EOM + The ${service} service could not be stopped. Please stop it manually and then re-run setup. + + Press ENTER to exit the installer. + EOM + + whiptail --title "Security Onion Setup" --msgbox "$message" 10 75 + exit 1 +} + whiptail_set_hostname() { [ -n "$TESTING" ] && return