v-delete-fastcgi-cache 2.5 KB

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