Skip to content

Commit 6f97485

Browse files
authored
prompt for restart setup
1 parent b1cb829 commit 6f97485

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

fastcgi_ops_root.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ fi
102102
shopt -s extglob
103103
this_script_path="${this_script_path%%+(/)}"
104104

105+
# Restart setup
106+
restart_auto_setup() {
107+
setup_flag="${this_script_path}/auto_setup_on"
108+
109+
# Remove the completed setup flag
110+
rm -f "$setup_flag"
111+
112+
# Restart the setup
113+
exec bash "${this_script_path}/${this_script_name}"
114+
}
115+
116+
# Prompt restart setup
117+
if [[ -f "${this_script_path}/auto_setup_on" ]]; then
118+
# User prompt for fresh restart auto setup
119+
read -rp $'\e[96mAuto setup has already been completed. Do you want to restart the setup? [Y/n]: \e[0m' restart_confirm
120+
if [[ $restart_confirm =~ ^[Yy]$ ]]; then
121+
restart_auto_setup
122+
fi
123+
fi
124+
105125
# Function to dynamically detect the location of nginx.conf
106126
detect_nginx_conf() {
107127
local DEFAULT_NGINX_CONF_PATHS=(
@@ -200,6 +220,7 @@ Wants=nginx.service
200220
201221
[Service]
202222
KillSignal=SIGKILL
223+
TimeoutStopSec=5
203224
Type=simple
204225
RemainAfterExit=yes
205226
User=root
@@ -219,7 +240,7 @@ NGINX_
219240
systemctl enable npp-wordpress.service > /dev/null 2>&1
220241

221242
# Start the service
222-
systemctl start npp-wordpress.service
243+
systemctl start npp-wordpress.service > /dev/null 2>&1
223244

224245
# Check if the service started successfully
225246
if systemctl is-active --quiet npp-wordpress.service; then
@@ -230,8 +251,12 @@ NGINX_
230251
echo -e "\e[91mError:\e[0m Systemd service \e[93mnpp-wordpress\e[0m failed to start."
231252
fi
232253
else
233-
systemctl stop npp-wordpress.service
234-
systemctl start npp-wordpress.service && echo -e "\e[92mSuccess:\e[0m Systemd service \e[93mnpp-wordpress\e[0m is re-started."
254+
systemctl stop npp-wordpress.service > /dev/null 2>&1
255+
sleep 6
256+
if systemctl is-active --quiet npp-wordpress.service; then
257+
systemctl kill npp-wordpress.service > /dev/null 2>&1
258+
fi
259+
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."
235260
fi
236261
}
237262

@@ -320,12 +345,23 @@ else
320345
for user in "${!fcgi[@]}"; do
321346
echo -e "User: \e[92m$user\e[0m, Nginx Cache Path: \e[93m${fcgi[$user]}\e[0m"
322347
done
323-
read -rp $'\e[96mDo you want to proceed with the above configuration? [Y/n]: \e[0m' confirm
348+
read -rp $'\e[96mDo you want to proceed with the above configuration? This takes a while.. [Y/n]: \e[0m' confirm
324349
if [[ $confirm =~ ^[Yy]$ || $confirm == "" ]]; then
325350
check_and_start_systemd_service && touch "${this_script_path}/auto_setup_on"
326351
else
327352
manual_setup
328353
fi
354+
else
355+
# Auto setup completed but systemd service is inactive, restart
356+
if ! systemctl is-active --quiet npp-wordpress.service; then
357+
systemctl stop npp-wordpress.service > /dev/null 2>&1
358+
sleep 6
359+
# force stop
360+
if systemctl is-active --quiet npp-wordpress.service; then
361+
systemctl kill npp-wordpress.service > /dev/null 2>&1
362+
fi
363+
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."
364+
fi
329365
fi
330366
fi
331367

0 commit comments

Comments
 (0)