add maintenance mode to nginx
This commit is contained in:
parent
ab2a9bfa4d
commit
6dd56b94ef
4 changed files with 184 additions and 1 deletions
69
maintenance_tool.sh
Normal file
69
maintenance_tool.sh
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/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_ROOTdocs/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 "================================================="
|
||||
Loading…
Add table
Add a link
Reference in a new issue