v-delete-fastcgi-cache 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # info: Disable FastCGI cache for nginx
  3. # options: USER DOMAIN [RESTART]
  4. #
  5. # example: v-delete-fastcgi-cache user domain.tld
  6. #
  7. # This function disables FastCGI cache for nginx
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Argument definition
  12. user=$1
  13. domain=$2
  14. restart=$3
  15. # Includes
  16. # shellcheck source=/etc/hestiacp/hestia.conf
  17. source /etc/hestiacp/hestia.conf
  18. # shellcheck source=/usr/local/hestia/func/main.sh
  19. source $HESTIA/func/main.sh
  20. # load config file
  21. source_conf "$HESTIA/conf/hestia.conf"
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '2' "$#" 'USER DOMAIN [RESTART]'
  26. is_format_valid 'user' 'domain' 'restart'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_valid 'web' 'DOMAIN' "$domain"
  29. is_object_valid 'web' 'DOMAIN' "$domain" "$FASTCGI_CACHE"
  30. # Perform verification if read-only mode is enabled
  31. check_hestia_demo_mode
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Load domain data
  36. parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
  37. # Remove FastCGI cache configuration
  38. if [ -f "$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf" ]; then
  39. rm -rf $HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf
  40. fi
  41. conf='/etc/nginx/conf.d/fastcgi_cache_pool.conf'
  42. if [ -f "$conf" ]; then
  43. sed -i "/ keys_zone=$domain/d" $conf
  44. if [ ! -s "$conf" ]; then
  45. rm -rf $conf
  46. fi
  47. fi
  48. # Delete FastCGI cache folder
  49. if [ -d "/var/cache/nginx/micro/$domain" ]; then
  50. rm -rf /var/cache/nginx/micro/$domain
  51. fi
  52. #----------------------------------------------------------#
  53. # Hestia #
  54. #----------------------------------------------------------#
  55. if [ -z "$FASTCGI_CACHE" ]; then
  56. add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
  57. fi
  58. if [ -z "$FASTCGI_DURATION" ]; then
  59. add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_DURATION' 'ALIAS'
  60. fi
  61. # Set FastCGI cache flag to disabled
  62. update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'no'
  63. update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_DURATION' '0s'
  64. # Restart web server
  65. if [ -n "$restart" ]; then
  66. $BIN/v-restart-web "$restart"
  67. check_result $? "Web server restart failed" > /dev/null
  68. fi
  69. # Logging
  70. $BIN/v-log-action "$user" "Info" "Web" "FastCGI cache disabled (Domain: $domain)."
  71. log_event "$OK" "$ARGUMENTS"
  72. exit