_common.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # =============================================================================
  3. # YUNOHOST 2.7 FORTHCOMING HELPERS
  4. # =============================================================================
  5. # Create a dedicated nginx config
  6. #
  7. # usage: ynh_add_nginx_config
  8. ynh_add_nginx_config () {
  9. finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
  10. ynh_backup_if_checksum_is_different "$finalnginxconf"
  11. sudo cp ../conf/nginx.conf "$finalnginxconf"
  12. # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
  13. # Substitute in a nginx config file only if the variable is not empty
  14. if test -n "${path_url:-}"; then
  15. ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
  16. fi
  17. if test -n "${domain:-}"; then
  18. ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf"
  19. fi
  20. if test -n "${port:-}"; then
  21. ynh_replace_string "__PORT__" "$port" "$finalnginxconf"
  22. fi
  23. if test -n "${app:-}"; then
  24. ynh_replace_string "__NAME__" "$app" "$finalnginxconf"
  25. fi
  26. if test -n "${final_path:-}"; then
  27. ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
  28. fi
  29. ynh_store_file_checksum "$finalnginxconf"
  30. sudo systemctl reload nginx
  31. }
  32. # Remove the dedicated nginx config
  33. #
  34. # usage: ynh_remove_nginx_config
  35. ynh_remove_nginx_config () {
  36. ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
  37. sudo systemctl reload nginx
  38. }
  39. # Create a dedicated php-fpm config
  40. #
  41. # usage: ynh_add_fpm_config
  42. ynh_add_fpm_config () {
  43. finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
  44. ynh_backup_if_checksum_is_different "$finalphpconf"
  45. sudo cp ../conf/php-fpm.conf "$finalphpconf"
  46. ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
  47. ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
  48. ynh_replace_string "__USER__" "$app" "$finalphpconf"
  49. sudo chown root: "$finalphpconf"
  50. ynh_store_file_checksum "$finalphpconf"
  51. if [ -e "../conf/php-fpm.ini" ]
  52. then
  53. finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
  54. ynh_backup_if_checksum_is_different "$finalphpini"
  55. sudo cp ../conf/php-fpm.ini "$finalphpini"
  56. sudo chown root: "$finalphpini"
  57. ynh_store_file_checksum "$finalphpini"
  58. fi
  59. sudo systemctl reload php5-fpm
  60. }
  61. # Remove the dedicated php-fpm config
  62. #
  63. # usage: ynh_remove_fpm_config
  64. ynh_remove_fpm_config () {
  65. ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
  66. ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1
  67. sudo systemctl reload php5-fpm
  68. }
  69. # Create a dedicated systemd config
  70. #
  71. # usage: ynh_add_systemd_config
  72. ynh_add_systemd_config () {
  73. finalsystemdconf="/etc/systemd/system/$app.service"
  74. ynh_backup_if_checksum_is_different "$finalsystemdconf"
  75. sudo cp ../conf/systemd.service "$finalsystemdconf"
  76. # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
  77. # Substitute in a nginx config file only if the variable is not empty
  78. if test -n "${final_path:-}"; then
  79. ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf"
  80. fi
  81. if test -n "${app:-}"; then
  82. ynh_replace_string "__APP__" "$app" "$finalsystemdconf"
  83. fi
  84. ynh_store_file_checksum "$finalsystemdconf"
  85. sudo chown root: "$finalsystemdconf"
  86. sudo systemctl enable $app
  87. sudo systemctl daemon-reload
  88. }
  89. # Remove the dedicated systemd config
  90. #
  91. # usage: ynh_remove_systemd_config
  92. ynh_remove_systemd_config () {
  93. finalsystemdconf="/etc/systemd/system/$app.service"
  94. if [ -e "$finalsystemdconf" ]; then
  95. sudo systemctl stop $app
  96. sudo systemctl disable $app
  97. ynh_secure_remove "$finalsystemdconf"
  98. fi
  99. }