config 6.8 KB

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