restore 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "Load 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_webpath_available $domain $path_url \
  31. || ynh_die "Path not available: ${domain}${path_url}"
  32. test ! -d $final_path \
  33. || ynh_die "There is already a directory: $final_path "
  34. #=================================================
  35. # STANDARD RESTORATION STEPS
  36. #=================================================
  37. # RESTORE THE NGINX CONFIGURATION
  38. #=================================================
  39. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  40. #=================================================
  41. # RESTORE THE APP MAIN DIR
  42. #=================================================
  43. ynh_print_info "Restore the app main directory"
  44. ynh_restore_file "$final_path"
  45. #=================================================
  46. # RECREATE THE DEDICATED USER
  47. #=================================================
  48. ynh_print_info "Recreate the dedicated user"
  49. # Create the dedicated user (if not existing)
  50. ynh_system_user_create $app
  51. #=================================================
  52. # RESTORE USER RIGHTS
  53. #=================================================
  54. # Restore permissions on app files
  55. chown -R root: $final_path
  56. #=================================================
  57. # RESTORE THE PHP-FPM CONFIGURATION
  58. #=================================================
  59. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  60. #=================================================
  61. # SPECIFIC RESTORATION
  62. #=================================================
  63. # REINSTALL DEPENDENCIES
  64. #=================================================
  65. ynh_print_info "Reinstall dependencies"
  66. # Define and install dependencies
  67. ynh_install_app_dependencies deb1 deb2
  68. #=================================================
  69. # RESTORE THE MYSQL DATABASE
  70. #=================================================
  71. ynh_print_info "Restore the mysql database"
  72. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  73. ynh_mysql_setup_db $db_name $db_name $db_pwd
  74. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  75. #=================================================
  76. # RESTORE SYSTEMD
  77. #=================================================
  78. ynh_print_info "Restore the systemd configuration"
  79. ynh_restore_file "/etc/systemd/system/$app.service"
  80. systemctl enable $app.service
  81. #=================================================
  82. # ADVERTISE SERVICE IN ADMIN PANEL
  83. #=================================================
  84. yunohost service add $app --log "/var/log/$app/$app.log"
  85. #=================================================
  86. # RESTORE THE CRON FILE
  87. #=================================================
  88. ynh_restore_file "/etc/cron.d/$app"
  89. #=================================================
  90. # RESTORE THE LOGROTATE CONFIGURATION
  91. #=================================================
  92. ynh_restore_file "/etc/logrotate.d/$app"
  93. #=================================================
  94. # GENERIC FINALIZATION
  95. #=================================================
  96. # RELOAD NGINX AND PHP-FPM
  97. #=================================================
  98. ynh_print_info "Reload nginx and php-fpm"
  99. systemctl reload php7.0-fpm
  100. systemctl reload nginx
  101. #=================================================
  102. # END OF SCRIPT
  103. #=================================================
  104. ynh_print_info "Restoration completed"