|
|
@@ -1,14 +1,14 @@
|
|
|
#!/bin/bash
|
|
|
-# info: Add FastCGI nginx support
|
|
|
-# options: USER DOMAIN [DEBUG]
|
|
|
+# info: Enable FastCGI cache for nginx
|
|
|
+# options: USER DOMAIN [DURATION] [DEBUG] [RESTART]
|
|
|
# labels: hestia web
|
|
|
#
|
|
|
-# example: v-add-fastcgi-cache user domain.tld
|
|
|
+# example: v-add-fastcgi-cache user domain.tld 30m
|
|
|
#
|
|
|
# The function enables FastCGI cache for nginx
|
|
|
+# Acceptable values for duration is time in seconds (10s) minutes (10m) or days (10d)
|
|
|
# Add "yes" as last parameter to append debug information to response headers
|
|
|
|
|
|
-
|
|
|
#----------------------------------------------------------#
|
|
|
# Variable&Function #
|
|
|
#----------------------------------------------------------#
|
|
|
@@ -16,7 +16,9 @@
|
|
|
# Argument definition
|
|
|
user=$1
|
|
|
domain=$2
|
|
|
-debug=$3
|
|
|
+duration=${3-2m}
|
|
|
+debug=${4-no}
|
|
|
+restart=${5-no}
|
|
|
|
|
|
# Includes
|
|
|
# shellcheck source=/usr/local/hestia/func/main.sh
|
|
|
@@ -36,6 +38,16 @@ is_object_unsuspended 'user' 'USER' "$user"
|
|
|
is_object_valid 'web' 'DOMAIN' "$domain"
|
|
|
is_object_unsuspended 'web' 'DOMAIN' "$domain"
|
|
|
|
|
|
+if ! [[ "$duration" =~ ^[0-9].*[s|m|d]$ ]]; then
|
|
|
+ echo "Invalid duration";
|
|
|
+ exit 2;
|
|
|
+fi
|
|
|
+
|
|
|
+if [[ "$duration" =~ ^[0].*[s|m|d]$ ]]; then
|
|
|
+ echo "Invalid duration";
|
|
|
+ exit 2;
|
|
|
+fi
|
|
|
+
|
|
|
# Perform verification if read-only mode is enabled
|
|
|
check_hestia_demo_mode
|
|
|
|
|
|
@@ -47,7 +59,7 @@ check_hestia_demo_mode
|
|
|
# Load domain data
|
|
|
parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
|
|
|
|
|
|
-# Check if nginx is not in proxy mode
|
|
|
+# Check that nginx is not in proxy mode
|
|
|
if [ "$WEB_SYSTEM" != 'nginx' ]; then
|
|
|
echo "Error: nginx is in proxy mode"
|
|
|
exit $E_NOTEXIST
|
|
|
@@ -65,7 +77,7 @@ status='$upstream_cache_status'
|
|
|
|
|
|
cat << EOF > $fastcgi
|
|
|
fastcgi_cache $domain;
|
|
|
- fastcgi_cache_valid 200 2m;
|
|
|
+ fastcgi_cache_valid 200 $duration;
|
|
|
fastcgi_cache_valid 301 302 10m;
|
|
|
fastcgi_cache_valid 404 10m;
|
|
|
fastcgi_cache_bypass $no_cache;
|
|
|
@@ -96,16 +108,22 @@ mkdir -p /var/cache/nginx/micro/$domain
|
|
|
# Hestia #
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
-if [ -z "$FASTCGI" ]; then
|
|
|
+if [ -z "$FASTCGI_CACHE" ]; then
|
|
|
add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
|
|
|
fi
|
|
|
+if [ -z "$FASTCGI_DURATION" ]; then
|
|
|
+ add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_DURATION' 'ALIAS'
|
|
|
+fi
|
|
|
|
|
|
# Set FastCGI cache flag to enabled
|
|
|
update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'yes'
|
|
|
+update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_DURATION' "$duration"
|
|
|
|
|
|
-# Restart web server
|
|
|
-$BIN/v-restart-web
|
|
|
-check_result $? "Web server restart failed" > /dev/null
|
|
|
+if [ "$restart" = "yes" ]; then
|
|
|
+ # Restart web server
|
|
|
+ $BIN/v-restart-web
|
|
|
+ check_result $? "Web server restart failed" > /dev/null
|
|
|
+fi
|
|
|
|
|
|
# Logging
|
|
|
log_history "Enabled FastCGI cache for $domain"
|