v-list-sys-nginx-config 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # info: list nginx config parameters
  3. # options: [FORMAT]
  4. #
  5. # The function for obtaining the list of nginx config parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. # JSON list function
  14. json_list() {
  15. eval $(echo "$config" |egrep "$keys" |tr -d ';'| awk '{print $1"="$2}')
  16. echo '{
  17. "CONFIG": {
  18. "worker_processes": "'$worker_processes'",
  19. "worker_connections": "'$worker_connections'",
  20. "send_timeout": "'$send_timeout'",
  21. "proxy_connect_timeout": "'$proxy_connect_timeout'",
  22. "proxy_send_timeout": "'$proxy_send_timeout'",
  23. "proxy_read_timeout": "'$proxy_read_timeout'",
  24. "client_max_body_size": "'$client_max_body_size'",
  25. "gzip": "'$gzip'",
  26. "gzip_comp_level": "'$gzip_comp_level'",
  27. "charset": "'$charset'",
  28. "config_path": "'$config_path'"
  29. }
  30. }'
  31. }
  32. # SHELL list function
  33. shell_list() {
  34. echo "$config" |egrep "$keys" |tr -d ';'
  35. echo "config_path $config_path"
  36. }
  37. # PLAIN list function
  38. plain_list() {
  39. echo "$config" |egrep "$keys" |tr -d ';'
  40. echo "config_path $config_path"
  41. }
  42. # CSV list function
  43. csv_list() {
  44. echo "$keys" |sed "s/ |/,/g"
  45. echo "$config" |egrep "$keys" |awk '{print $2}' |tr -d ';' |tr '\n' ','
  46. echo
  47. }
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. # Defining config path
  52. config_path='/etc/nginx/nginx.conf'
  53. # Defining keys
  54. keys="worker_processes |worker_connections |send_timeout"
  55. keys="$keys |proxy_connect_timeout |proxy_send_timeout"
  56. keys="$keys |proxy_read_timeout |client_max_body_size"
  57. keys="$keys |gzip |gzip_comp_level |charset "
  58. # Reading nginx config
  59. config=$(cat $config_path)
  60. # Listing data
  61. case $format in
  62. json) json_list ;;
  63. plain) plain_list ;;
  64. csv) csv_list ;;
  65. shell) shell_list |column -t;;
  66. esac
  67. #----------------------------------------------------------#
  68. # Vesta #
  69. #----------------------------------------------------------#
  70. exit