#!/usr/bin/env bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2024 - License: MIT ## ########################################################################### # The following script will reload monit upon configuration changes and # # the script is meant to be ran as a standalone long-runnng process. # # Note that the script uses "inotifywait" and leverages filesystem file # # notifiacations for a lower CPU usage and only asynchronously reloads # # the configuration when changes have been made (ie: instead of polling). # ########################################################################### # alarm(2) function alarm { sleep $1 monit reload } ALARM_PID=0 trap '{ test $ALARM_PID = 0 || kill -9 $ALARM_PID; }' KILL QUIT TERM EXIT INT HUP MONIT_DIRECTORY=/conf inotifywait -q -m "$MONIT_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 fi alarm "5" & ALARM_PID=$! done