feat: Restart salt-master on config changes
Automatically restart salt-master when config changes are detected.
This commit is contained in:
@@ -11,6 +11,7 @@ SALT_LOG_ROTATE_FREQUENCY=${SALT_LOG_ROTATE_FREQUENCY:-weekly}
|
||||
SALT_LOG_ROTATE_RETENTION=${SALT_LOG_ROTATE_RETENTION:-52}
|
||||
|
||||
# https://docs.saltstack.com/en/latest/ref/configuration/master.html
|
||||
SALT_RESTART_MASTER_ON_CONFIG_CHANGE=${SALT_RESTART_MASTER_ON_CONFIG_CHANGE:-false}
|
||||
|
||||
##### Logging settings #####
|
||||
# https://docs.saltstack.com/en/latest/ref/configuration/master.html#master-logging-settings
|
||||
|
||||
@@ -432,6 +432,27 @@ EOF
|
||||
|
||||
}
|
||||
|
||||
function configure_config_reloader()
|
||||
{
|
||||
rm -f /etc/supervisor/conf.d/config-reloader.conf
|
||||
[ "${SALT_RESTART_MASTER_ON_CONFIG_CHANGE}" == true ] || return 0
|
||||
|
||||
echo "Configuring config reloader ..."
|
||||
|
||||
# configure supervisord to start config-reloader
|
||||
cat > /etc/supervisor/conf.d/config-reloader.conf <<EOF
|
||||
[program:config-reloader]
|
||||
priority=20
|
||||
directory=/tmp
|
||||
command=/usr/local/sbin/config-reloader
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile=${SALT_LOGS_DIR}/supervisor/%(program_name)s.log
|
||||
stderr_logfile=${SALT_LOGS_DIR}/supervisor/%(program_name)s.log
|
||||
EOF
|
||||
}
|
||||
|
||||
#--- FUNCTION -------------------------------------------------------------------------------------------------------
|
||||
# NAME: initialize_system
|
||||
# DESCRIPTION: Initialize the system.
|
||||
@@ -445,6 +466,7 @@ function initialize_system()
|
||||
configure_salt_master
|
||||
configure_salt_api
|
||||
configure_salt_formulas
|
||||
configure_config_reloader
|
||||
setup_salt_keys
|
||||
setup_ssh_keys
|
||||
rm -rf /var/run/supervisor.sock
|
||||
|
||||
17
assets/sbin/config-reloader
Executable file
17
assets/sbin/config-reloader
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# shellcheck source=assets/runtime/functions.sh
|
||||
FUNCTIONS_FILE="${SALT_RUNTIME_DIR}/functions.sh"
|
||||
source "${FUNCTIONS_FILE}"
|
||||
|
||||
function check_for_config_changes()
|
||||
{
|
||||
inotifywait -qq --recursive \
|
||||
--event modify,move,create,delete \
|
||||
"${SALT_CONFS_DIR}"
|
||||
}
|
||||
|
||||
while check_for_config_changes; do
|
||||
log_info "Configuration changes detected. Reloading salt-master ..."
|
||||
supervisorctl restart salt-master
|
||||
done
|
||||
Reference in New Issue
Block a user