upgrade 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. ### Settings are automatically loaded as bash variables
  8. ### in every app script context, therefore typically these will exist:
  9. ### - $domain
  10. ### - $path
  11. ### - $language
  12. ### - $install_dir
  13. ### - $port
  14. ### ...
  15. ### In the context of upgrade,
  16. ### - resources are automatically provisioned / updated / deleted (depending on existing resources)
  17. ### - a safety backup is automatically created by the core and will be restored if the upgrade fails
  18. #=================================================
  19. # STOP SYSTEMD SERVICE
  20. #=================================================
  21. ynh_script_progression "Stopping $app's systemd service..."
  22. ynh_systemctl --service="$app" --action="stop"
  23. #=================================================
  24. # ENSURE DOWNWARD COMPATIBILITY
  25. #=================================================
  26. ynh_script_progression "Ensuring downward compatibility..."
  27. ynh_app_setting_set_default --key=php_upload_max_filesize --value=50M
  28. ynh_app_setting_set_default --key=php_post_max_size --value=50M
  29. ### N.B. : the following setting migration snippets are provided as *EXAMPLES*
  30. ### of what you may want to do in some cases (e.g. a setting was not defined on
  31. ### some legacy installs and you therefore want to initiaze stuff during upgrade)
  32. # If db_name doesn't exist, create it
  33. # ynh_app_setting_set_default --key=db_name --value="$(ynh_sanitize_dbid --db_name=$app)"
  34. # If install_dir doesn't exist, create it
  35. # ynh_app_setting_set_default --key=install_dir --value="/var/www/$app"
  36. #=================================================
  37. # DOWNLOAD, CHECK AND UNPACK SOURCE
  38. #=================================================
  39. ynh_script_progression "Upgrading source files..."
  40. ### ynh_setup_source can wipe the destination dir if called with --full_replace.
  41. ### On upgrade, that is certainly what you want, to remove any old source file that
  42. ### does not exist in the new version of the software.
  43. ### You can list with --keep every file/directory to *not* wipe or overwrite,
  44. ### useful for configuration files, data directories, or plugins.
  45. # Download, check integrity, uncompress and patch the source from manifest.toml
  46. ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=".env data"
  47. ### $install_dir will automatically be initialized with some decent
  48. ### permissions by default... however, you may need to recursively reapply
  49. ### ownership to all files such as after the ynh_setup_source step
  50. chown -R "$app:www-data" "$install_dir"
  51. #=================================================
  52. # UPDATE A CONFIG FILE
  53. #=================================================
  54. ynh_script_progression "Updating $app's configuration files..."
  55. ### Same as during install
  56. ###
  57. ### The file will automatically be backed-up if it's found to be manually modified (because
  58. ### ynh_config_add keeps track of the file's checksum)
  59. ynh_config_add --template="some_config_file" --destination="$install_dir/some_config_file"
  60. # FIXME: this should be handled by the core in the future
  61. ### You may need to use chmod 600 instead of 400,
  62. ### for example if the app is expected to be able to modify its own config
  63. chmod 400 "$install_dir/some_config_file"
  64. chown "$app:$app" "$install_dir/some_config_file"
  65. ### For more complex cases where you want to replace stuff using regexes,
  66. ### you shoud rely on ynh_replace (which is basically a wrapper for sed)
  67. ### When doing so, you also need to manually call ynh_store_file_checksum
  68. ###
  69. ### ynh_replace --match="match_string" --replace="replace_string" --file="$install_dir/some_config_file"
  70. ### ynh_store_file_checksum "$install_dir/some_config_file"
  71. #=================================================
  72. # REAPPLY SYSTEM CONFIGURATION
  73. #=================================================
  74. ynh_script_progression "Upgrading system configurations related to $app..."
  75. ### This should be a literal copypaste of what happened in the install's "System configuration" section
  76. ynh_config_add_phpfpm
  77. ynh_config_add_nginx
  78. ynh_config_add_systemd
  79. yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log"
  80. ynh_config_add_logrotate
  81. ynh_config_add_fail2ban --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
  82. #=================================================
  83. # START SYSTEMD SERVICE
  84. #=================================================
  85. ynh_script_progression "Starting $app's systemd service..."
  86. ynh_systemctl --service="$app" --action="start"
  87. #=================================================
  88. # END OF SCRIPT
  89. #=================================================
  90. ynh_script_progression "Upgrade of $app completed"