Update optimize/optimize-server.sh

This commit is contained in:
HHF Technology 2024-11-27 14:25:58 +05:30
parent 4539691c05
commit f86f7d09d5

View file

@ -4,13 +4,13 @@
# VARIABLES # # VARIABLES #
#-----------------------------------# #-----------------------------------#
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/optimize/optimize-server.sh" this_script_url="https://example.com/optimize-server.sh"
this_script_name="Server Optimization Script" this_script_name="Server Optimization Script"
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh" formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
scriptname=$0 scriptname=$0
# Configuration URLs # Configuration URLs
NGINX_CONF_URL="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/optimize/nginx.conf" NGINX_CONF_URL="https://git.hhf.technology/hhf/script-management-cloudpanel/src/branch/main/optimize/nginx.conf"
MARIADB_CONF_URL="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/optimize/100-cloudpanel.cnf" MARIADB_CONF_URL="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/optimize/100-cloudpanel.cnf"
# Configuration paths # Configuration paths
@ -37,6 +37,7 @@ download_formatter() {
source ./task_formatter.sh || { echo "Error: Failed to source task_formatter.sh"; exit 1; } source ./task_formatter.sh || { echo "Error: Failed to source task_formatter.sh"; exit 1; }
} }
# Call the download_formatter function
download_formatter download_formatter
#-----------------------------------# #-----------------------------------#
@ -59,6 +60,7 @@ check_os_compatibility() {
return 1 return 1
fi fi
echo "OS compatibility check passed"
return 0 return 0
} }
@ -74,6 +76,7 @@ check_nginx_version() {
return 1 return 1
fi fi
echo "Nginx version check passed"
return 0 return 0
} }
@ -88,6 +91,7 @@ check_mariadb() {
return 1 return 1
fi fi
echo "MariaDB check passed"
return 0 return 0
} }
@ -115,6 +119,7 @@ optimize_nginx() {
# Replace the configuration # Replace the configuration
mv "$NGINX_CONF.new" "$NGINX_CONF" mv "$NGINX_CONF.new" "$NGINX_CONF"
echo "Nginx optimization completed"
return 0 return 0
} }
@ -126,18 +131,19 @@ optimize_mariadb() {
if ! wget --no-check-certificate "$MARIADB_CONF_URL" -O "$MARIADB_CONF.new"; then if ! wget --no-check-certificate "$MARIADB_CONF_URL" -O "$MARIADB_CONF.new"; then
echo "Error: Failed to download MariaDB configuration" echo "Error: Failed to download MariaDB configuration"
return 1 return 1
} fi
# Verify the downloaded configuration # Verify the downloaded configuration
if ! mysqld --validate-config --defaults-file="$MARIADB_CONF.new"; then if ! mysqld --validate-config --defaults-file="$MARIADB_CONF.new"; then
echo "Error: Invalid MariaDB configuration" echo "Error: Invalid MariaDB configuration"
rm "$MARIADB_CONF.new" rm "$MARIADB_CONF.new"
return 1 return 1
} fi
# Replace the configuration # Replace the configuration
mv "$MARIADB_CONF.new" "$MARIADB_CONF" mv "$MARIADB_CONF.new" "$MARIADB_CONF"
echo "MariaDB optimization completed"
return 0 return 0
} }
@ -150,19 +156,20 @@ restart_nginx() {
if ! nginx -t; then if ! nginx -t; then
echo "Error: Invalid Nginx configuration detected before restart" echo "Error: Invalid Nginx configuration detected before restart"
return 1 return 1
} fi
if ! systemctl restart nginx; then if ! systemctl restart nginx; then
echo "Error: Failed to restart Nginx" echo "Error: Failed to restart Nginx"
return 1 return 1
} fi
# Verify service is running # Verify service is running
if ! systemctl is-active --quiet nginx; then if ! systemctl is-active --quiet nginx; then
echo "Error: Nginx failed to start" echo "Error: Nginx failed to start"
return 1 return 1
} fi
echo "Nginx restarted successfully"
return 0 return 0
} }
@ -170,14 +177,15 @@ restart_mariadb() {
if ! systemctl restart mariadb; then if ! systemctl restart mariadb; then
echo "Error: Failed to restart MariaDB" echo "Error: Failed to restart MariaDB"
return 1 return 1
} fi
# Verify service is running # Verify service is running
if ! systemctl is-active --quiet mariadb; then if ! systemctl is-active --quiet mariadb; then
echo "Error: MariaDB failed to start" echo "Error: MariaDB failed to start"
return 1 return 1
} fi
echo "MariaDB restarted successfully"
return 0 return 0
} }