From cfbf27a755c1692010e155aa81e96d799230da4e Mon Sep 17 00:00:00 2001 From: Jeremy Poulin Date: Tue, 13 Jan 2026 10:05:51 -0500 Subject: [PATCH] feat: add instructions for shutdown cronjob --- cron/SETUP-INSTRUCTIONS.md | 57 ++++++++++++++++++++++++++++++++++++++ cron/shutdown-cluster.sh | 31 +++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 cron/SETUP-INSTRUCTIONS.md create mode 100755 cron/shutdown-cluster.sh diff --git a/cron/SETUP-INSTRUCTIONS.md b/cron/SETUP-INSTRUCTIONS.md new file mode 100644 index 0000000..d2cb968 --- /dev/null +++ b/cron/SETUP-INSTRUCTIONS.md @@ -0,0 +1,57 @@ +# Cluster Shutdown Cron Job Setup + +## Installation + +1. **Copy the script to your home directory:** + ```bash + cp ./shutdown-cluster.sh ~/bin/shutdown-cluster.sh + chmod +x ~/bin/shutdown-cluster.sh + ``` + +2. **Add to crontab:** + ```bash + crontab -e + ``` + +3. **Add this line to run at 6pm daily:** + ``` + 0 18 * * * $HOME/bin/shutdown-cluster.sh + ``` + + Or if you want it to run Monday-Friday only: + ``` + 0 18 * * 1-5 $HOME/bin/shutdown-cluster.sh + ``` + +## Cron Schedule Format +``` +* * * * * +│ │ │ │ │ +│ │ │ │ └─── Day of week (0-7, where 0 and 7 are Sunday) +│ │ │ └───── Month (1-12) +│ │ └─────── Day of month (1-31) +│ └───────── Hour (0-23) +└─────────── Minute (0-59) +``` + +## Check Logs + +Logs are written to: `~/.logs/shutdown-cluster.log` + +```bash +tail -f ~/.logs/shutdown-cluster.log +``` + +## Verify Cron Job + +List your cron jobs: +```bash +crontab -l +``` + +## Test Manually + +You can test the script manually: +```bash +~/bin/shutdown-cluster.sh +``` diff --git a/cron/shutdown-cluster.sh b/cron/shutdown-cluster.sh new file mode 100755 index 0000000..d7d3241 --- /dev/null +++ b/cron/shutdown-cluster.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Shutdown cluster at 6pm daily +# This script changes to the deploy directory, runs make shutdown-cluster stop, then returns + +set -e + +LOG_FILE="$HOME/.logs/shutdown-cluster.log" +mkdir -p "$(dirname "$LOG_FILE")" + +echo "=== $(date '+%Y-%m-%d %H:%M:%S') - Starting cluster shutdown ===" >> "$LOG_FILE" + +# Save current directory +ORIGINAL_DIR=$(pwd) + +# Change to deploy directory +cd "$HOME/Projects/jaypoulz/two-node-toolbox/deploy" || { + echo "ERROR: Failed to change to deploy directory" >> "$LOG_FILE" + exit 1 +} + +# Run make command +if make shutdown-cluster stop >> "$LOG_FILE" 2>&1; then + echo "SUCCESS: Cluster shutdown completed" >> "$LOG_FILE" +else + echo "ERROR: make shutdown-cluster stop failed with exit code $?" >> "$LOG_FILE" +fi + +# Return to original directory +cd "$ORIGINAL_DIR" || true + +echo "=== Shutdown complete ===" >> "$LOG_FILE"