v-delete-fastcgi-cache 2.4 KB

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