[feat] Add timeout for salt services to stop during reinstall init

This commit is contained in:
William Wernert
2020-12-01 21:18:24 -05:00
parent c2e7e42509
commit 38028a543a
2 changed files with 37 additions and 1 deletions

View File

@@ -1382,6 +1382,12 @@ reserve_group_ids() {
reinstall_init() { reinstall_init() {
info "Putting system in state to run setup again" 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 # Disable all scheduled jobs
@@ -1390,7 +1396,24 @@ reinstall_init() {
fi fi
# Kill any salt processes (safely) # 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 # Remove all salt configs
rm -rf /etc/salt/global /etc/salt/minion /etc/salt/master /etc/salt/pki/* rm -rf /etc/salt/global /etc/salt/minion /etc/salt/master /etc/salt/pki/*

View File

@@ -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() { whiptail_set_hostname() {
[ -n "$TESTING" ] && return [ -n "$TESTING" ] && return