diff --git a/bin/cron/check_services b/bin/cron/check_services new file mode 100755 index 0000000..8ac3267 --- /dev/null +++ b/bin/cron/check_services @@ -0,0 +1,35 @@ +#!/bin/bash +SHELL=/bin/bash +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +## launch vps check-service and if the result is not empty: send a notification +## If the result is empty, remove the state file +## ``vps check-service`` output is filled only if there is a problem + + +STATE_WORKING_DIR="/var/run/elab-manage" +mkdir -p "$STATE_WORKING_DIR" +STATE_CHECK_SERVICE="$STATE_WORKING_DIR/check_service.state" + + +vps_check_service=$(vps check-service) + +if [ -n "$vps_check_service" ]; then + msg="New" + if [ -e "$STATE_CHECK_SERVICE" ]; then + if [[ "$(cat "$STATE_CHECK_SERVICE")" == "$vps_check_service" ]]; then + exit 0 + fi + msg="Changed" + fi + + echo "$vps_check_service" > "$STATE_CHECK_SERVICE" + title="alert: check-service failed" + message="$vps_check_service" + echo "MESSAGE: '$message'" >&2 + send -c check-service.alert -t "$title ($msg)" "$message" +else + if [ -e "$STATE_CHECK_SERVICE" ]; then + rm "$STATE_CHECK_SERVICE" + fi +fi diff --git a/bin/elab-update b/bin/elab-update index 4038e6c..bc96c33 100755 --- a/bin/elab-update +++ b/bin/elab-update @@ -6,13 +6,13 @@ REPO_PATH="/opt/apps/elab-manage" # Function to update the git repository update_repo() { echo "Updating the git repository..." - cd "$REPO_PATH" || { - echo "Error: Unable to find the repository at $REPO_PATH"; + cd "$REPO_PATH" || { + echo "Error: Unable to find the repository at $REPO_PATH"; exit 1; } - git pull -r || { - echo "Error: Unable to update the repository"; - exit 1; + git pull -r || { + echo "Error: Unable to update the repository"; + exit 1; } } @@ -22,9 +22,9 @@ update_repo() { update_symlinks() { echo "Updating symbolic links for cron.daily..." # Update or add new symbolic links for cron.daily and cron.hourly - for dir in "cron."{daily,hourly}; do + for dir in "cron."{d,daily,hourly,mounthly,weekly}; do find -L /etc/$dir -maxdepth 1 -type l -ilname $REPO_PATH/etc/$dir\* -delete - ln -sf $REPO_PATH/etc/$dir/* /etc/$dir + ln -sf $REPO_PATH/etc/$dir/* /etc/$dir done echo "Symbolic links have been successfully updated." diff --git a/etc/cron.d/check_services b/etc/cron.d/check_services new file mode 100755 index 0000000..1c077bc --- /dev/null +++ b/etc/cron.d/check_services @@ -0,0 +1,4 @@ +SHELL=/bin/bash +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + +*/10 * * * * root lock check_services_elabore -v -D -p 10 -k -c "/opt/apps/elab-manage/bin/cron/check_services" 2>&1 | logger -t check-services-elabore \ No newline at end of file