Skip to content

Commit 79290ad

Browse files
committed
Fix start and stop services script for php-fpm (both single and multiphp) and add input validation
1 parent fa5e775 commit 79290ad

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

bin/v-restart-service

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: restart service
3-
# options: service
3+
# options: service [RESTART]
44
#
55
# The function restarts system service.
66

@@ -22,7 +22,7 @@ PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
2222
# Verifications #
2323
#----------------------------------------------------------#
2424

25-
check_args '1' "$#" 'SERVICE'
25+
check_args '1' "$#" 'SERVICE [RESTART]'
2626
is_format_valid 'service' 'restart'
2727

2828
#----------------------------------------------------------#
@@ -72,6 +72,11 @@ for service in $service_list; do
7272
fi
7373
done
7474

75+
76+
#----------------------------------------------------------#
77+
# Hestia #
78+
#----------------------------------------------------------#
79+
7580
# Logging
7681
log_event "$OK" "$ARGUMENTS"
7782

bin/v-start-service

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,36 @@ source $HESTIA/func/main.sh
2121
#----------------------------------------------------------#
2222

2323
check_args '1' "$#" 'SERVICE'
24+
is_format_valid 'service'
2425

2526

2627
#----------------------------------------------------------#
2728
# Action #
2829
#----------------------------------------------------------#
2930

30-
if [ "$service" != 'iptables' ]; then
31-
systemctl start $service > /dev/null 2>&1
32-
check_result $? "ERROR: $service start failed" $E_RESTART
31+
if [ "$service" = "php-fpm" ];then
32+
for php_ver in $(multiphp_versions); do
33+
service_list="${service_list} php${php_ver}-fpm"
34+
done
3335
else
34-
$BIN/v-update-firewall
35-
check_result $? "ERROR: $service start failed" $E_RESTART
36+
service_list="$service"
3637
fi
3738

39+
for service in $service_list; do
40+
if [ "$service" = "iptables" ]; then
41+
$BIN/v-update-firewall
42+
else
43+
systemctl start $service > /dev/null 2>&1
44+
fi
45+
check_result $? "ERROR: $service start failed" $E_RESTART
46+
done
47+
3848

3949
#----------------------------------------------------------#
4050
# Hestia #
4151
#----------------------------------------------------------#
4252

53+
# Logging
54+
log_event "$OK" "$ARGUMENTS"
55+
4356
exit

bin/v-stop-service

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ source $HESTIA/func/main.sh
2121
#----------------------------------------------------------#
2222

2323
check_args '1' "$#" 'SERVICE'
24+
is_format_valid 'service'
2425

2526
# Perform verification if read-only mode is enabled
2627
check_hestia_demo_mode
@@ -30,17 +31,29 @@ check_hestia_demo_mode
3031
# Action #
3132
#----------------------------------------------------------#
3233

33-
if [ "$service" != 'iptables' ]; then
34-
systemctl stop $service >/dev/null 2>&1
35-
check_result $? "ERROR: $service stop failed" $E_RESTART
34+
if [ "$service" = "php-fpm" ];then
35+
for php_ver in $(multiphp_versions); do
36+
service_list="${service_list} php${php_ver}-fpm"
37+
done
3638
else
37-
$BIN/v-stop-firewall
38-
check_result $? "ERROR: $service stop failed" $E_RESTART
39+
service_list="$service"
3940
fi
4041

42+
for service in $service_list; do
43+
if [ "$service" = "iptables" ]; then
44+
$BIN/v-stop-firewall
45+
else
46+
systemctl stop $service >/dev/null 2>&1
47+
fi
48+
check_result $? "ERROR: $service stop failed" $E_RESTART
49+
done
50+
4151

4252
#----------------------------------------------------------#
4353
# Hestia #
4454
#----------------------------------------------------------#
4555

56+
# Logging
57+
log_event "$OK" "$ARGUMENTS"
58+
4659
exit

0 commit comments

Comments
 (0)