#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-maintenance-enable.txt ########################## #### path: /var/www/ss-maintenance-enable ########################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Activates maintenance.html that Nginx parses to temporarily disable frontend ######### #### module version: Nginx 1.18.x ################################################################## #### sourced by: ss-install ######################################################################## #### bash aliases: ss main [enable|on], ss maintenance [enable|on] ################################# #################################################################################################### ## source ss-config ## source /var/www/ss-config ## source ss-functions ## source /var/www/ss-functions ## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS #################################################################################################### #### TABLE OF CONTENTS (SS-Maintenance-Enable) ##################################################### #################################################################################################### ## this is a brief summary of the different code snippets you will find in this script ## ## each section should be commented so you understand what is being accomplished ## ## A. Touch Timestamp File ## B. Message (Begin Script) ## C. Enable Maintenance Mode (Via Nginx) ## D. Purge Cache (Nginx) #################################################################################################### #### A. SS-Maintenance-Enable: Touch Timestamp File ################################################ #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## ss_touch "${TIMESTAMP_SS_MAINTENANCE_ENABLE}" #################################################################################################### #### B. SS-Maintenance-Enable: Message (Begin Script) ############################################## #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be noticed by sudo users who manually call ss core bash scripts ## ## echo message ## ss_echo "${COLOR_INFO}Running ss-maintenance-enable... ${COLOR_RESET}" #################################################################################################### #### C. SS-Maintenance-Enable: Activate Maintenance Mode (Via Nginx) ############################### #################################################################################################### ## here is the critical snippet that copies the maintenance.html file to /var/www/html ## ## after the file is noticed by Nginx it should activate within a few page views ## if [[ "${SS_APP}" != "mysql" ]]; then ## perms ## ss_mkdir /var/www/html ## retrieve latest maintenance.html file (if not exists) ## if [[ ! -f "/var/www/meta/maintenance.html" ]]; then ss_wget "${TMP_MAINTENANCE_HTML}" "${MIRROR_MAINTENANCE_HTML}" ss_cp "${TMP_MAINTENANCE_HTML}" "${PATH_MAINTENANCE_HTML}" chown www-data:www-data "${PATH_MAINTENANCE_HTML}" chmod 0644 "${PATH_MAINTENANCE_HTML}" ## 0644 fi ## whitelabel maintenance.html ## if [[ -n "${WHITELABEL_BRAND}" ]]; then sed -i "s|https://slickstack.io|${WHITELABEL_HOMEPAGE}|g" "${PATH_MAINTENANCE_HTML}" sed -i "s|SlickStack|${WHITELABEL_BRAND}|g" "${PATH_MAINTENANCE_HTML}" fi ## activate maintenance.html ## ss_rm "${PATH_MAINTENANCE_HTML_LIVE}" ss_cp "${PATH_MAINTENANCE_HTML}" "${PATH_MAINTENANCE_HTML_LIVE}" chown www-data:www-data "${PATH_MAINTENANCE_HTML_LIVE}" chmod 0644 "${PATH_MAINTENANCE_HTML_LIVE}" ## 0644 fi #################################################################################################### ### D. SS-Maintenance-Enable: Purge Cache (Nginx) ################################################## #################################################################################################### ## run ss-purge-nginx ## source "${PATH_SS_PURGE_NGINX}" #################################################################################################### #### PLACEHOLDER: Reset Permissions (SlickStack Scripts) ########################################### #################################################################################################### ## we include this permissions reset in all cron jobs and bash scripts for redundancy ## ## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ## ## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS ## SNIPPET: ss bash scripts, ss cron jobs ## UPDATED: 02JUL2022 chown root:root /var/www/ss* ## must be root:root chown root:root /var/www/crons/*cron* ## must be root:root chown root:root /var/www/crons/custom/*cron* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://stackoverflow.com/questions/5600448/how-to-setup-custom-503-error-page-in-nginx-that-intercepts-all-requests ## SS_EOF