keep-data

Nginx added support for stack keep-data option.
This commit is contained in:
Cristhian Martínez Ochoa 2022-11-26 17:07:33 -07:00
parent 196af0b931
commit fc0f89f299
3 changed files with 70 additions and 37 deletions

View file

@ -177,10 +177,13 @@ nginx_install() {
[[ ! -d /etc/nginx/sites-enabled ]] && sudo mkdir /etc/nginx/sites-enabled
[[ ! -d /etc/nginx/apps.d ]] && sudo mkdir /etc/nginx/apps.d
# In reinstalation (after purge with keep-data) this file don't exist
if [[ -f /etc/nginx/conf.d/default.conf ]]; then
sudo sed -i 's/listen.*80;/listen 80 default_server;/' /etc/nginx/conf.d/default.conf
sudo sed -i 's/listen.*\[::\]:80;/listen [::]:80 default_server;/' /etc/nginx/conf.d/default.conf
sudo mv /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/default
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
fi
sudo nginx -t && sudo systemctl start nginx
sudo systemctl enable nginx
@ -321,6 +324,9 @@ nginx_optim() {
sudo sed -i '/ SERVER_NAME /s/#//' /etc/nginx/fastcgi_params
sudo sed -i '/ SERVER_NAME /s/^/#/' /etc/nginx/fastcgi_params
# Needed to prevent duplicates in server-reset, also in reinstallation (after purge with keep-data)
sudo sed -i '/WebinolyCustom/,/WebinolyCustomEnd/{/.*/d}' /etc/nginx/fastcgi_params
echo '# WebinolyCustom
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SERVER_NAME $host;
@ -497,11 +503,16 @@ nginx_tool_site() {
# Tools site creation
[[ -z $(conf_read tools-port) ]] && conf_write tools-port $tools_port_default
# Don't overwrite in case that exist (after purge with keep-data, for instance)
if [[ ! -f /etc/nginx/sites-available/$(conf_read tools-port) ]]; then
sudo site $(conf_read tools-port) -empty > /dev/null 2>&1
sudo cp /opt/webinoly/templates/general/admin_tools.conf /etc/nginx/sites-available/$(conf_read tools-port)
sudo sed -i "s/<port>/$(conf_read tools-port)/g" /etc/nginx/sites-available/$(conf_read tools-port)
sudo nginx -t && sudo systemctl reload nginx
fi
# Don't overwrite in case that exist (after purge with keep-data, for instance)
if [[ ! -f /var/www/$(conf_read tools-port)/htdocs ]]; then
# Nginx Status Page
sudo touch /var/www/$(conf_read tools-port)/htdocs/nginx_status
@ -511,6 +522,7 @@ nginx_tool_site() {
Disallow: /' > /var/www/$(conf_read tools-port)/htdocs/robots.txt
sudo chmod 644 /var/www/$(conf_read tools-port)/htdocs/robots.txt
sudo chown -R www-data:www-data /var/www/$(conf_read tools-port)/htdocs
fi
# in case php was installed before nginx
[[ $(conf_read php) == "true" && ! -f /var/www/$(conf_read tools-port)/htdocs/php/index.php ]] && php_tool_site

View file

@ -414,7 +414,6 @@ server_reset() {
# Regenerate NGINX conf files
if [[ $(conf_read nginx-optim) == "true" && $server_reset =~ ^(nginx|all)$ ]]; then
sudo sed -i '/WebinolyCustom/,/WebinolyCustomEnd/{/.*/d}' /etc/nginx/fastcgi_params
sudo rm -rf /etc/nginx/common
#sudo rm -rf /etc/nginx/conf.d/* - Some custom files can be in this folder, so don't remove it, just the core files!
[[ -f /etc/nginx/conf.d/upstream.conf ]] && sudo rm -rf /etc/nginx/conf.d/upstream.conf

View file

@ -40,6 +40,20 @@ purge_mysql_client() {
conf_write mysql-client purged
}
purge_nginx_tools() {
# Remove additional tools
[[ $(conf_read login-www-data) == "true" ]] && webinoly -login-www-data=off
[[ $(conf_read nginx-tool-ssl) == "true" ]] && stack -letsencrypt -purge=force
[[ $(conf_read nginx-tool-bkp) == "true" ]] && stack -backups -purge=force
[[ $(conf_read mysql-tool-pma) == "true" ]] && stack -pma -purge=force
[[ -d /var/www ]] && sudo rm -rf /var/www/*
[[ -n $(conf_read tools-site) ]] && conf_delete tools-site -commented
[[ -n $(conf_read default-response) ]] && conf_delete default-response -commented
[[ -n $(conf_read default-site) ]] && conf_delete default-site
}
#############################################
######## Delete/Purge some stack ########
#############################################
@ -48,6 +62,14 @@ if [[ -n $purge && ( -n $html || -n $nginx ) ]]; then
api-events_update pn1
if [[ $(conf_read nginx) != "true" ]]; then
echo "${dim}Nginx is not installed, hence can not be deleted! ${end}"
purge_nginx_tools # In case of nginx purged with keep-data before.
# Just in case, nginx purged with keep-data before can preserve some remanent data, for instance!
if [[ -d /etc/nginx ]]; then
sudo apt -y purge nginx
echo "${gre}${dim}Nginx remanent data found and removed!${end}"
fi
clear_force_flag
else
if [[ $(conf_read force-flag) != "true" ]]; then
@ -64,7 +86,9 @@ if [[ -n $purge && ( -n $html || -n $nginx ) ]]; then
fi
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
if [[ $(conf_read force-flag) == "true" && $force == 1 ]]; then
if [[ $nginx == "keep-data" ]]; then
answer="N"
elif [[ $(conf_read force-flag) == "true" && $force == 1 ]]; then
answer="Y"
else
echo ""
@ -79,19 +103,16 @@ if [[ -n $purge && ( -n $html || -n $nginx ) ]]; then
site -delete-all=force
fi
# Remove tools-site
[[ $(conf_read mysql-tool-pma) == "true" ]] && stack -pma -purge=force
sudo rm -rf /var/www/html
sudo rm -rf /var/www/$(conf_read tools-port)
conf_delete tools-site -commented
[[ $(conf_read login-www-data) == "true" ]] && webinoly -login-www-data=off
[[ $(conf_read nginx-tool-ssl) == "true" ]] && stack -letsencrypt -purge=force
[[ $(conf_read nginx-tool-bkp) == "true" ]] && stack -backups -purge=force
purge_autoremove="true"
sudo systemctl stop nginx
if [[ $nginx != "keep-data" ]]; then
purge_nginx_tools
sudo apt -y purge nginx
else
sudo apt -y remove nginx
echo "${blu}Nginx data (including your sites) and configuration was NOT removed.${end}"
fi
# APT-KEY deprecated in 22.04
if [[ $(lsb_release -c | cut -d':' -f 2 | xargs) =~ ^(bionic|focal)$ ]]; then
@ -106,12 +127,6 @@ if [[ -n $purge && ( -n $html || -n $nginx ) ]]; then
sudo rm -rf /etc/apt/sources.list.d/nginx.list
fi
# Remove SSL Cron
if [[ -f /var/spool/cron/crontabs/root ]]; then
sudo sed -i '/MAILTO=/d' /var/spool/cron/crontabs/root
sudo sed -i '/certbot renew/d' /var/spool/cron/crontabs/root
fi
[ -L $CURRENT_HOME/www ] && sudo rm $CURRENT_HOME/www
[ -L $CURRENT_HOME/sites-available ] && sudo rm $CURRENT_HOME/sites-available
@ -301,7 +316,14 @@ elif [[ -n $purge && -n $letsencrypt ]]; then
fi
if [[ $answer == [Yy] || $(conf_read force-flag) == "true" ]]; then
sudo snap remove certbot
# Remove SSL Cron
if [[ -f /var/spool/cron/crontabs/root ]]; then
sudo sed -i '/MAILTO=/d' /var/spool/cron/crontabs/root
sudo sed -i '/certbot renew/d' /var/spool/cron/crontabs/root
fi
# To remove a snap without generating a snapshot, use the additional --purge argument
sudo snap remove certbot --purge
[[ -L /usr/bin/certbot ]] && sudo rm -rf /usr/bin/certbot
conf_write nginx-tool-ssl purged
echo ""