11#! /bin/bash
22# info: Add FastCGI nginx support
3- # options: USER DOMAIN [DEBUG]
3+ # options: USER DOMAIN [LENTGH] [ DEBUG] [RESTART ]
44# labels: hestia web
55#
6- # example: v-add-fastcgi-cache user domain.tld
6+ # example: v-add-fastcgi-cache user domain.tld 30m
77#
88# The function enables FastCGI cache for nginx
9+ # For Length only use time in seconds (10s) minutes (10m) or days (10d)
910# Add "yes" as last parameter to append debug information to response headers
1011
11-
1212# ----------------------------------------------------------#
1313# Variable&Function #
1414# ----------------------------------------------------------#
1515
1616# Argument definition
1717user=$1
1818domain=$2
19- debug=$3
19+ length=${3-30m}
20+ debug=${4-no}
21+ restart=${5-no}
2022
2123# Includes
2224source $HESTIA /func/main.sh
@@ -34,6 +36,10 @@ is_object_unsuspended 'user' 'USER' "$user"
3436is_object_valid ' web' ' DOMAIN' " $domain "
3537is_object_unsuspended ' web' ' DOMAIN' " $domain "
3638
39+ if ! [[ " $length " =~ ^[0-9].* [s| m| d]$ ]]; then
40+ echo " Invalid length" ;
41+ exit 2;
42+ fi
3743# Perform verification if read-only mode is enabled
3844check_hestia_demo_mode
3945
@@ -94,16 +100,21 @@ mkdir -p /var/cache/nginx/micro/$domain
94100# Hestia #
95101# ----------------------------------------------------------#
96102
97- if [ -z " $FASTCGI " ]; then
103+ if [ -z " $FASTCGI_CACHE " ]; then
98104 add_object_key " web" ' DOMAIN' " $domain " ' FASTCGI_CACHE' ' ALIAS'
99105fi
106+ if [ -z " $FASTCGI_LENGTH " ]; then
107+ add_object_key " web" ' DOMAIN' " $domain " ' $FASTCGI_LENGTH' ' ALIAS'
108+ fi
100109
101110# Set FastCGI cache flag to enabled
102111update_object_value ' web' ' DOMAIN' " $domain " ' $FASTCGI_CACHE' ' yes'
103112
104- # Restart web server
105- $BIN /v-restart-web
106- check_result $? " Web server restart failed" > /dev/null
113+ if [ " $restart " = " yes" ]; then
114+ # Restart web server
115+ $BIN /v-restart-web
116+ check_result $? " Web server restart failed" > /dev/null
117+ fi
107118
108119# Logging
109120log_history " Enabled FastCGI cache for $domain "
0 commit comments