Skip to content

Commit

Permalink
prompt for restart setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hsntgm authored Jul 7, 2024
1 parent b1cb829 commit 6f97485
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions fastcgi_ops_root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ fi
shopt -s extglob
this_script_path="${this_script_path%%+(/)}"

# Restart setup
restart_auto_setup() {
setup_flag="${this_script_path}/auto_setup_on"

# Remove the completed setup flag
rm -f "$setup_flag"

# Restart the setup
exec bash "${this_script_path}/${this_script_name}"
}

# Prompt restart setup
if [[ -f "${this_script_path}/auto_setup_on" ]]; then
# User prompt for fresh restart auto setup
read -rp $'\e[96mAuto setup has already been completed. Do you want to restart the setup? [Y/n]: \e[0m' restart_confirm
if [[ $restart_confirm =~ ^[Yy]$ ]]; then
restart_auto_setup
fi
fi

# Function to dynamically detect the location of nginx.conf
detect_nginx_conf() {
local DEFAULT_NGINX_CONF_PATHS=(
Expand Down Expand Up @@ -200,6 +220,7 @@ Wants=nginx.service
[Service]
KillSignal=SIGKILL
TimeoutStopSec=5
Type=simple
RemainAfterExit=yes
User=root
Expand All @@ -219,7 +240,7 @@ NGINX_
systemctl enable npp-wordpress.service > /dev/null 2>&1

# Start the service
systemctl start npp-wordpress.service
systemctl start npp-wordpress.service > /dev/null 2>&1

# Check if the service started successfully
if systemctl is-active --quiet npp-wordpress.service; then
Expand All @@ -230,8 +251,12 @@ NGINX_
echo -e "\e[91mError:\e[0m Systemd service \e[93mnpp-wordpress\e[0m failed to start."
fi
else
systemctl stop npp-wordpress.service
systemctl start npp-wordpress.service && echo -e "\e[92mSuccess:\e[0m Systemd service \e[93mnpp-wordpress\e[0m is re-started."
systemctl stop npp-wordpress.service > /dev/null 2>&1
sleep 6
if systemctl is-active --quiet npp-wordpress.service; then
systemctl kill npp-wordpress.service > /dev/null 2>&1
fi
systemctl start npp-wordpress.service > /dev/null 2>&1 && echo -e "\e[92mSuccess:\e[0m Systemd service \e[93mnpp-wordpress\e[0m is re-started."
fi
}

Expand Down Expand Up @@ -320,12 +345,23 @@ else
for user in "${!fcgi[@]}"; do
echo -e "User: \e[92m$user\e[0m, Nginx Cache Path: \e[93m${fcgi[$user]}\e[0m"
done
read -rp $'\e[96mDo you want to proceed with the above configuration? [Y/n]: \e[0m' confirm
read -rp $'\e[96mDo you want to proceed with the above configuration? This takes a while.. [Y/n]: \e[0m' confirm
if [[ $confirm =~ ^[Yy]$ || $confirm == "" ]]; then
check_and_start_systemd_service && touch "${this_script_path}/auto_setup_on"
else
manual_setup
fi
else
# Auto setup completed but systemd service is inactive, restart
if ! systemctl is-active --quiet npp-wordpress.service; then
systemctl stop npp-wordpress.service > /dev/null 2>&1
sleep 6
# force stop
if systemctl is-active --quiet npp-wordpress.service; then
systemctl kill npp-wordpress.service > /dev/null 2>&1
fi
systemctl start npp-wordpress.service > /dev/null 2>&1 && echo -e "\e[92mSuccess:\e[0m Auto setup has already been completed but systemd service is not active. Systemd service \e[93mnpp-wordpress\e[0m is re-started."
fi
fi
fi

Expand Down

0 comments on commit 6f97485

Please sign in to comment.