photo26/maintenance_tool.sh

69 lines
2.6 KiB
Bash
Executable file

#!/bin/bash
# Title: Site Maintenance Mode Toggle Script
# Description: Activates or deactivates site maintenance mode by toggling the presence of a flag file.
# Activation: Creating $FLAG_FILE
# Deactivation: Deleting $FLAG_FILE
# --- CONFIGURATION ---
# IMPORTANT: Change this path to the root directory of your website.
# The script MUST have write permissions to this directory.
SITE_ROOT="/var/www/photos/photo21"
FLAG_FILE="$SITE_ROOT/docs/maintenance.flag"
# ---------------------
# Function to display current status
function display_status() {
echo "================================================="
echo " SITE MAINTENANCE MODE TOOL"
echo "================================================="
echo "Target Directory: $SITE_ROOT"
if [ -f "$FLAG_FILE" ]; then
echo -e "\033[31mCURRENT STATUS: ACTIVE (Site is DOWN for Maintenance)\033[0m"
echo "Flag file present at: $FLAG_FILE"
else
echo -e "\033[32mCURRENT STATUS: INACTIVE (Site is UP and Running)\033[0m"
echo "Flag file is missing."
fi
echo "-------------------------------------------------"
}
# Function to toggle mode based on current status
function toggle_mode() {
if [ -f "$FLAG_FILE" ]; then
# Maintenance is ON, offer to turn it OFF
read -r -p "Maintenance mode is ACTIVE. DEACTIVATE it? (y/N): " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm -f "$FLAG_FILE"
if [ $? -eq 0 ]; then
echo -e "\n\033[32mSUCCESS:\033[0m Maintenance mode DEACTIVATED. Site should be live."
else
echo -e "\n\033[31mERROR:\033[0m Failed to remove '$FLAG_FILE'. Check script and directory permissions."
fi
else
echo "Action cancelled. Maintenance mode remains ACTIVE."
fi
else
# Maintenance is OFF, offer to turn it ON
read -r -p "Maintenance mode is INACTIVE. ACTIVATE it? (y/N): " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
touch "$FLAG_FILE"
if [ $? -eq 0 ]; then
echo -e "\n\033[31mSUCCESS:\033[0m Maintenance mode ACTIVATED. Site should now show the maintenance page."
else
echo -e "\n\033[31mERROR:\033[0m Failed to create '$FLAG_FILE'. Check script and directory permissions."
fi
else
echo "Action cancelled. Maintenance mode remains INACTIVE."
fi
fi
}
# Main execution
display_status
toggle_mode
echo "================================================="
echo "Script finished."
echo "================================================="