Skip to content

Commit 3ae017e

Browse files
authored
add trap SIGINT
1 parent b66b2f5 commit 3ae017e

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

fastcgi_ops_root.sh

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19+
manual_setup() {
20+
echo -e "\n\e[91mCanceled:\e[0m Automated Setup has been canceled by the user. Proceeding to manual setup."
21+
# Provide instructions for manual configuration
22+
echo -e "\e[36mTo set up manual configuration, create a file named \e[95m'manual-configs.nginx' \e[0m \e[36min the same directory as this script."
23+
echo -e "Each entry should follow the format: 'PHP-FPM_user FastCGI_cache_path', with one entry per virtual host."
24+
echo -e "Ensure that every new website added to your host is accompanied by an entry in this file."
25+
echo -e "After making changes, remember to restart the script \e[95mfastcgi_ops_root.sh\e[0m."
26+
exit 1
27+
}
28+
29+
# user confirmation and handle ctrl+c
30+
trap manual_setup SIGINT
1931

2032
# Get help before and interrupt
2133
help() {
@@ -143,7 +155,7 @@ while IFS= read -r VHOST; do
143155
# Extract PHP-FPM users from running processes, excluding root
144156
while read -r user; do
145157
ACTIVE_PHP_FPM_USERS+=("$user")
146-
done < <(ps -eo user:30,cmd | grep "[p]hp-fpm:.*$VHOST" | awk '{print $1}' | awk '!seen[$0]++' | grep -v "root")
158+
done < <(ps -eo user:30,cmd | grep "[p]hp-fpm:.*$VHOST" | awk '{print $1}' | awk '!seen[$0]++' | grep -v "root")
147159
done <<< "$ACTIVE_VHOSTS"
148160

149161
# Check if the PHP-FPM user's name is present in the FastCGI cache path
@@ -173,7 +185,7 @@ check_and_start_systemd_service() {
173185
# Generate systemd service file
174186
cat <<- NGINX_ > "$service_file"
175187
[Unit]
176-
Description=FastCGI Operations Service
188+
Description=NPP Wordpress Plugin Cache Operations Service
177189
After=network.target nginx.service local-fs.target
178190
Wants=nginx.service
179191
@@ -202,13 +214,13 @@ NGINX_
202214

203215
# Check if the service started successfully
204216
if systemctl is-active --quiet npp-wordpress.service; then
205-
echo -e "\e[92mSuccess:\e[0m Service \e[93mwp-fcgi-notify\e[0m is started."
217+
echo -e "\e[92mSuccess:\e[0m Service \e[93mnpp-wordpress\e[0m is started."
206218
else
207-
echo -e "\e[91mError:\e[0m Service \e[93mwp-fcgi-notify\e[0m failed to start."
219+
echo -e "\e[91mError:\e[0m Service \e[93mnpp-wordpress\e[0m failed to start."
208220
fi
209221
else
210222
systemctl stop npp-wordpress.service
211-
systemctl start npp-wordpress.service && echo -e "\e[92mSuccess:\e[0m Service \e[93mwp-fcgi-notify\e[0m is re-started."
223+
systemctl start npp-wordpress.service && echo -e "\e[92mSuccess:\e[0m Service \e[93mnpp-wordpress\e[0m is re-started."
212224
fi
213225
}
214226

@@ -260,6 +272,7 @@ if [[ -f "${this_script_path}/manual-configs.nginx" ]]; then
260272

261273
fcgi["$user"]="$cache_path"
262274
done < "${this_script_path}/manual-configs.nginx"
275+
263276
# Check setup already completed or not
264277
if ! [[ -f "${this_script_path}/manual_setup_on" ]]; then
265278
check_and_start_systemd_service && touch "${this_script_path}/manual_setup_on"
@@ -300,13 +313,7 @@ else
300313
if [[ $confirm =~ ^[Yy]$ || $confirm == "" ]]; then
301314
check_and_start_systemd_service && touch "${this_script_path}/auto_setup_on"
302315
else
303-
echo -e "\e[91mCanceled:\e[0m Automated Setup has been canceled by the user. Proceeding to manual setup."
304-
# Provide instructions for manual configuration
305-
echo -e "\n\e[36mTo set up manual configuration, create a file named \e[95m'manual-configs.nginx' \e[0m \e[36min the same directory as this script."
306-
echo -e "Each entry should follow the format: 'PHP-FPM_user FastCGI_cache_path', with one entry per virtual host."
307-
echo -e "Ensure that every new website added to your host is accompanied by an entry in this file."
308-
echo -e "After making changes, remember to restart the script \e[95mfastcgi_ops_root.sh\e[0m."
309-
exit 0
316+
manual_setup
310317
fi
311318
fi
312319
fi

0 commit comments

Comments
 (0)