102
102
shopt -s extglob
103
103
this_script_path=" ${this_script_path%% +(/ )} "
104
104
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
+
105
125
# Function to dynamically detect the location of nginx.conf
106
126
detect_nginx_conf () {
107
127
local DEFAULT_NGINX_CONF_PATHS=(
@@ -200,6 +220,7 @@ Wants=nginx.service
200
220
201
221
[Service]
202
222
KillSignal=SIGKILL
223
+ TimeoutStopSec=5
203
224
Type=simple
204
225
RemainAfterExit=yes
205
226
User=root
@@ -219,7 +240,7 @@ NGINX_
219
240
systemctl enable npp-wordpress.service > /dev/null 2>&1
220
241
221
242
# Start the service
222
- systemctl start npp-wordpress.service
243
+ systemctl start npp-wordpress.service > /dev/null 2>&1
223
244
224
245
# Check if the service started successfully
225
246
if systemctl is-active --quiet npp-wordpress.service; then
@@ -230,8 +251,12 @@ NGINX_
230
251
echo -e " \e[91mError:\e[0m Systemd service \e[93mnpp-wordpress\e[0m failed to start."
231
252
fi
232
253
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."
235
260
fi
236
261
}
237
262
@@ -320,12 +345,23 @@ else
320
345
for user in " ${! fcgi[@]} " ; do
321
346
echo -e " User: \e[92m$user \e[0m, Nginx Cache Path: \e[93m${fcgi[$user]} \e[0m"
322
347
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
324
349
if [[ $confirm =~ ^[Yy]$ || $confirm == " " ]]; then
325
350
check_and_start_systemd_service && touch " ${this_script_path} /auto_setup_on"
326
351
else
327
352
manual_setup
328
353
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
329
365
fi
330
366
fi
331
367
0 commit comments