restore 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source ../settings/scripts/_common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # MANAGE SCRIPT FAILURE
  11. #=================================================
  12. ynh_clean_setup () {
  13. #### Remove this function if there's nothing to clean before calling the remove script.
  14. true
  15. }
  16. # Exit if an error occurs during the execution of the script
  17. ynh_abort_if_errors
  18. #=================================================
  19. # LOAD SETTINGS
  20. #=================================================
  21. ynh_print_info "Loading settings..."
  22. app=$YNH_APP_INSTANCE_NAME
  23. domain=$(ynh_app_setting_get $app domain)
  24. path_url=$(ynh_app_setting_get $app path)
  25. final_path=$(ynh_app_setting_get $app final_path)
  26. db_name=$(ynh_app_setting_get $app db_name)
  27. #=================================================
  28. # CHECK IF THE APP CAN BE RESTORED
  29. #=================================================
  30. ynh_print_info "Validating restoration parameters..."
  31. ynh_webpath_available $domain $path_url \
  32. || ynh_die "Path not available: ${domain}${path_url}"
  33. test ! -d $final_path \
  34. || ynh_die "There is already a directory: $final_path "
  35. #=================================================
  36. # STANDARD RESTORATION STEPS
  37. #=================================================
  38. # RESTORE THE NGINX CONFIGURATION
  39. #=================================================
  40. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  41. #=================================================
  42. # RESTORE THE APP MAIN DIR
  43. #=================================================
  44. ynh_print_info "Restoring the app main directory..."
  45. ynh_restore_file "$final_path"
  46. #=================================================
  47. # RECREATE THE DEDICATED USER
  48. #=================================================
  49. ynh_print_info "Recreating the dedicated system user..."
  50. # Create the dedicated user (if not existing)
  51. ynh_system_user_create $app
  52. #=================================================
  53. # RESTORE USER RIGHTS
  54. #=================================================
  55. # Restore permissions on app files
  56. chown -R root: $final_path
  57. #=================================================
  58. # RESTORE THE PHP-FPM CONFIGURATION
  59. #=================================================
  60. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  61. #=================================================
  62. # SPECIFIC RESTORATION
  63. #=================================================
  64. # REINSTALL DEPENDENCIES
  65. #=================================================
  66. ynh_print_info "Reinstalling dependencies..."
  67. # Define and install dependencies
  68. ynh_install_app_dependencies deb1 deb2
  69. #=================================================
  70. # RESTORE THE MYSQL DATABASE
  71. #=================================================
  72. ynh_print_info "Restoring the MySQL database..."
  73. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  74. ynh_mysql_setup_db $db_name $db_name $db_pwd
  75. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  76. #=================================================
  77. # RESTORE SYSTEMD
  78. #=================================================
  79. ynh_print_info "Restoring the systemd configuration..."
  80. ynh_restore_file "/etc/systemd/system/$app.service"
  81. systemctl enable $app.service
  82. #=================================================
  83. # ADVERTISE SERVICE IN ADMIN PANEL
  84. #=================================================
  85. yunohost service add $app --log "/var/log/$app/$app.log"
  86. #=================================================
  87. # RESTORE THE CRON FILE
  88. #=================================================
  89. ynh_restore_file "/etc/cron.d/$app"
  90. #=================================================
  91. # RESTORE THE LOGROTATE CONFIGURATION
  92. #=================================================
  93. ynh_restore_file "/etc/logrotate.d/$app"
  94. #=================================================
  95. # GENERIC FINALIZATION
  96. #=================================================
  97. # RELOAD NGINX AND PHP-FPM
  98. #=================================================
  99. ynh_print_info "Reloading nginx web server and php-fpm..."
  100. systemctl reload php7.0-fpm
  101. systemctl reload nginx
  102. #=================================================
  103. # END OF SCRIPT
  104. #=================================================
  105. ynh_print_info "Restoration completed for $app"