config 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # RETRIEVE ARGUMENTS
  11. #=================================================
  12. app=$YNH_APP_INSTANCE_NAME
  13. fpm_config_dir=$(ynh_app_setting_get --app=$app --key=fpm_config_dir)
  14. #=================================================
  15. # SPECIFIC CODE
  16. #=================================================
  17. # LOAD VALUES
  18. #=================================================
  19. # Load the real value from the app config or elsewhere.
  20. # Then get the value from the form.
  21. # If the form has a value for a variable, take the value from the form,
  22. # Otherwise, keep the value from the app config.
  23. # Overwrite setupVars.conf file
  24. old_overwrite_setupvars="$(ynh_app_setting_get --app=$app --key=overwrite_setupvars)"
  25. overwrite_setupvars="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS:-$old_overwrite_setupvars}"
  26. # Overwrite pihole-FTL.conf file
  27. old_overwrite_ftl="$(ynh_app_setting_get --app=$app --key=overwrite_ftl)"
  28. overwrite_ftl="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL:-$old_overwrite_ftl}"
  29. # Overwrite nginx configuration
  30. old_overwrite_nginx="$(ynh_app_setting_get --app=$app --key=overwrite_nginx)"
  31. overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}"
  32. # Overwrite php-fpm configuration
  33. old_overwrite_phpfpm="$(ynh_app_setting_get --app=$app --key=overwrite_phpfpm)"
  34. overwrite_phpfpm="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM:-$old_overwrite_phpfpm}"
  35. # Type of admin mail configuration
  36. old_admin_mail_html="$(ynh_app_setting_get --app=$app --key=admin_mail_html)"
  37. admin_mail_html="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}"
  38. # Footprint for php-fpm
  39. old_fpm_footprint="$(ynh_app_setting_get --app=$app --key=fpm_footprint)"
  40. fpm_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT:-$old_fpm_footprint}"
  41. # Free footprint value for php-fpm
  42. # Check if fpm_footprint is an integer
  43. if [ "$fpm_footprint" -eq "$fpm_footprint" ] 2> /dev/null
  44. then
  45. # If fpm_footprint is an integer, that's a numeric value for the footprint
  46. old_free_footprint=$fpm_footprint
  47. fpm_footprint=specific
  48. else
  49. old_free_footprint=0
  50. fi
  51. free_footprint="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT:-$old_free_footprint}"
  52. # Usage for php-fpm
  53. old_fpm_usage="$(ynh_app_setting_get --app=$app --key=fpm_usage)"
  54. fpm_usage="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE:-$old_fpm_usage}"
  55. # php_forced_max_children for php-fpm
  56. old_php_forced_max_children="$(ynh_app_setting_get --app=$app --key=php_forced_max_children)"
  57. # If php_forced_max_children isn't into settings.yml, get the current value from the fpm config
  58. if [ -z "$old_php_forced_max_children" ]; then
  59. old_php_forced_max_children="$(grep "^pm.max_children" "$fpm_config_dir/pool.d/$app.conf" | awk '{print $3}')"
  60. fi
  61. php_forced_max_children="${YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN:-$old_php_forced_max_children}"
  62. #=================================================
  63. # SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
  64. #=================================================
  65. show_config() {
  66. # here you are supposed to read some config file/database/other then print the values
  67. # ynh_return "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
  68. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_SETUPVARS=$overwrite_setupvars"
  69. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_FTL=$overwrite_ftl"
  70. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx"
  71. ynh_return "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_PHPFPM=$overwrite_phpfpm"
  72. ynh_return "YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE=$admin_mail_html"
  73. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FOOTPRINT=$fpm_footprint"
  74. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FREE_FOOTPRINT=$free_footprint"
  75. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_USAGE=$fpm_usage"
  76. ynh_return "YNH_CONFIG_MAIN_PHP_FPM_CONFIG_FORCE_MAX_CHILDREN=$php_forced_max_children"
  77. }
  78. #=================================================
  79. # MODIFY THE CONFIGURATION
  80. #=================================================
  81. apply_config() {
  82. #=================================================
  83. # MODIFY OVERWRITTING SETTINGS
  84. #=================================================
  85. # Set overwrite_setupvars
  86. ynh_app_setting_set --app=$app --key=overwrite_setupvars --value="$overwrite_setupvars"
  87. # Set overwrite_ftl
  88. ynh_app_setting_set --app=$app --key=overwrite_ftl --value="$overwrite_ftl"
  89. # Set overwrite_nginx
  90. ynh_app_setting_set --app=$app --key=overwrite_nginx --value="$overwrite_nginx"
  91. # Set overwrite_phpfpm
  92. ynh_app_setting_set --app=$app --key=overwrite_phpfpm --value="$overwrite_phpfpm"
  93. #=================================================
  94. # MODIFY EMAIL SETTING
  95. #=================================================
  96. # Set admin_mail_html
  97. ynh_app_setting_set --app=$app --key=admin_mail_html --value="$admin_mail_html"
  98. #=================================================
  99. # RECONFIGURE PHP-FPM
  100. #=================================================
  101. if [ "$fpm_usage" != "$old_fpm_usage" ] || \
  102. [ "$fpm_footprint" != "$old_fpm_footprint" ] || \
  103. [ "$free_footprint" != "$old_free_footprint" ] || \
  104. [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
  105. then
  106. # If fpm_footprint is set to 'specific', use $free_footprint value.
  107. if [ "$fpm_footprint" = "specific" ]
  108. then
  109. fpm_footprint=$free_footprint
  110. fi
  111. if [ "$php_forced_max_children" != "$old_php_forced_max_children" ]
  112. then
  113. # Set php_forced_max_children
  114. if [ $php_forced_max_children -ne 0 ]
  115. then
  116. ynh_app_setting_set --app=$app --key=php_forced_max_children --value="$php_forced_max_children"
  117. else
  118. # If the value is set to 0, remove the setting
  119. ynh_app_setting_delete --app=$app --key=php_forced_max_children
  120. fi
  121. fi
  122. if [ "$fpm_footprint" != "0" ]
  123. then
  124. ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint --dedicated_service
  125. else
  126. ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below."
  127. fi
  128. fi
  129. }
  130. #=================================================
  131. # GENERIC FINALIZATION
  132. #=================================================
  133. # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
  134. #=================================================
  135. case $1 in
  136. show) show_config;;
  137. apply) apply_config;;
  138. esac