From ce8e5d9ca781c05e7776266f7bdb270f3be7017a Mon Sep 17 00:00:00 2001 From: Rod Wright Date: Mon, 23 Feb 2026 06:31:11 -0500 Subject: [PATCH] Modified to use apache conf template and take app offline during upgrade --- install.sh | 76 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index bb719f1..e347366 100755 --- a/install.sh +++ b/install.sh @@ -201,11 +201,38 @@ then abort_exit else # proceed with upgrade - - # take app offline during upgrade + # put app in maintenance mode + echo "Putting the applocation in maintenance mode..." + # make sure mod_rewrite is enabled + if [[ ! -e "$APACHE_CONF_DIR/../mods-enabled/rewrite.load" ]] + then + a2enmod -q rewrite + systemctl restart apache2 + fi + # disable the app a2disconf -q $install_loc_in systemctl reload apache2 - + # modify the apache conf file + if ! grep -q "RewriteEngine" "$APACHE_CONF_DIR/$install_loc_in.conf" + then + # this is an old version of the conf file. Replace with new version + cp -f default-apache.conf $APACHE_CONF_DIR/$install_loc_in.conf + sed -i "s|_APPNAME_|$APP_NAME|g" $APACHE_CONF_DIR/$install_loc_in.conf + sed -i "s|_BASEURL_|$install_loc_in|g" $APACHE_CONF_DIR/$install_loc_in.conf + sed -i "s|_DOCROOTIN_|$doc_root_in|g" $APACHE_CONF_DIR/$install_loc_in.conf + fi + sed -i "s|#Rewrite|Rewrite|g" $APACHE_CONF_DIR/$install_loc_in.conf + # copy in the default maintenancemode.php if it's not already there + if [[ ! -e "$install_path/maintenancemode.php" ]] + then + cp maintenancemode.php $install_path/ + # modify the maintenancemode.php file + sed -i "s|_APPNAME_|$APP_NAME|g" $install_path/maintenancemode.php + fi + # re-enable the app in maintenance mode + a2enconf -q $install_loc_in + systemctl reload apache2 + datestamp=$(date +%Y-%m-%d_%H:%M:%S) backupdir=backups/$datestamp mkdir -p $backupdir @@ -231,8 +258,8 @@ then echo "Backing up current installation to the package directory." cp -R $install_path $backupdir/$install_loc_in-$datestamp-backup - # delete all existing installation files except db.php - find $install_path/ -mindepth 1 -not -name 'db.php' -delete + # delete all existing installation files except db.php and maintenancemode.php + find $install_path/ -mindepth 1 ! \( -name 'db.php' -o -name 'maintenancemode.php' \) -delete echo "Performing database updates..." # apply database updates from sql file @@ -271,6 +298,17 @@ then chown -R $httpd_user_group $install_path echo "Backups of the previous openlog files and the previous database were made" echo "and are located in the $backupdir directory." + + # take app out of maintenance mode + echo "Taking the app out of maintenance mode..." + # disable the app + a2disconf -q $install_loc_in + systemctl reload apache2 + # modify the apache conf file + sed -i "s|Rewrite|#Rewrite|g" $APACHE_CONF_DIR/$install_loc_in.conf + # re-enable the app in production mode + a2enconf -q $install_loc_in + systemctl reload apache2 fi else # This was a mistake. Exit now to avoid clobbering another app. @@ -369,10 +407,16 @@ else if [[ ! -f "$install_path/db.php" ]] then cp db.php.template $install_path/db.php - sed -i "s/DBNAME/$new_db_name/g" $install_path/db.php - sed -i "s/DBUSER/$db_user/g" $install_path/db.php - sed -i "s/DBPASS/$db_pass/g" $install_path/db.php - sed -i "s/APPNAME/$APP_NAME/g" $install_path/db.php + sed -i "s|DBNAME|$new_db_name|g" $install_path/db.php + sed -i "s|DBUSER|$db_user|g" $install_path/db.php + sed -i "s|DBPASS|$db_pass|g" $install_path/db.php + sed -i "s|APPNAME|$APP_NAME|g" $install_path/db.php + fi + # Create maintenancemode.php if it doesn't exist + if [[ ! -f "$install_path/maintenancemode.php" ]] + then + cp maintenancemode.php $install_path/maintenancemode.php + sed -i "s|_APPNAME_|$APP_NAME|g" $install_path/maintenancemode.php fi # copy distribution to install location @@ -412,15 +456,11 @@ then fi if [[ "$operation" == "installed" ]] then - echo "# $APP_NAME default Apache configuration" > $APACHE_CONF_DIR/$base_url.conf - echo "" >> $APACHE_CONF_DIR/$base_url.conf - echo "Alias /$base_url $doc_root_in/$base_url" >> $APACHE_CONF_DIR/$base_url.conf - echo "" >> $APACHE_CONF_DIR/$base_url.conf - echo "" >> $APACHE_CONF_DIR/$base_url.conf - echo " AllowOverride Options" >> $APACHE_CONF_DIR/$base_url.conf - echo " Options FollowSymLinks" >> $APACHE_CONF_DIR/$base_url.conf - echo " DirectoryIndex index.php" >> $APACHE_CONF_DIR/$base_url.conf - echo "" >> $APACHE_CONF_DIR/$base_url.conf + cp -f default-apache.conf $APACHE_CONF_DIR/$base_url.conf + sed -i "s|_APPNAME_|$APP_NAME|g" $APACHE_CONF_DIR/$base_url.conf + sed -i "s|_BASEURL_|$base_url|g" $APACHE_CONF_DIR/$base_url.conf + sed -i "s|_DOCROOTIN_|$doc_root_in|g" $APACHE_CONF_DIR/$base_url.conf + echo -n "The apache2 $base_url configuration must be enabled. Would you like to do that now? [Y/n] :" read enconf if [[ "$enconf" == "" || "$enconf" == "Y" || "$enconf" == "y" ]]