#!/usr/bin/env bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2024 - License: MIT ## ########################################################################### # This script can be used to make a daemon reload its configuration # # whenever a change occurs within a defined directory, presumably the # # same directory where the configuration is stored in the first place. # # # # The script requires the "inotify-tools" package to be installed or # # whatever other package provides the "inotifywait" command line tool. # # Next, the script must be modified to make the necessary changes in the # # "CONFIGURATION" section where the path to the directory to be watched # # is specified and to also define a command that should be used to reload # # the daemon. Note that whatever the command contains, must also be # # installed for the script to work. # # # # The script has to be ran permanently for the entire duration that the # # processes that it is monitoring is running. This can be accomplished by # # starting the script using "supervisord" or any other tool that can run # # daemons, including bash scripts. # ########################################################################### ########################################################################### # CONFIGURATION # ########################################################################### MONITOR_DIRECTORY=/data RELOAD_COMMAND="kill -s HUP `pidof freeradius`" ########################################################################### # INTERNALS # ########################################################################### # alarm(2) function alarm { sleep $1 eval $RELOAD_COMMAND } ALARM_PID=0 trap '{ test $ALARM_PID = 0 || kill -9 $ALARM_PID; }' KILL QUIT TERM EXIT INT HUP inotifywait -q -m "$MONITOR_DIRECTORY" -r \ -e "modify" -e "create" -e "delete" | \ while IFS=$'\n' read -r LINE; do if [ -d /proc/"$ALARM_PID" ]; then kill -9 $ALARM_PID &>/dev/null || true fi alarm "5" & ALARM_PID=$! done