config 6.8 KB

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