restore 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. app=$YNH_APP_INSTANCE_NAME
  22. domain=$(ynh_app_setting_get $app domain)
  23. path_url=$(ynh_app_setting_get $app path)
  24. final_path=$(ynh_app_setting_get $app final_path)
  25. db_name=$(ynh_app_setting_get $app db_name)
  26. #=================================================
  27. # CHECK IF THE APP CAN BE RESTORED
  28. #=================================================
  29. ynh_webpath_available $domain $path_url \
  30. || ynh_die "Path not available: ${domain}${path_url}"
  31. test ! -d $final_path \
  32. || ynh_die "There is already a directory: $final_path "
  33. #=================================================
  34. # STANDARD RESTORATION STEPS
  35. #=================================================
  36. # RESTORE THE NGINX CONFIGURATION
  37. #=================================================
  38. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  39. #=================================================
  40. # RESTORE THE APP MAIN DIR
  41. #=================================================
  42. ynh_restore_file "$final_path"
  43. #=================================================
  44. # RESTORE THE MYSQL DATABASE
  45. #=================================================
  46. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  47. ynh_mysql_setup_db $db_name $db_name $db_pwd
  48. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  49. #=================================================
  50. # RECREATE THE DEDICATED USER
  51. #=================================================
  52. # Create the dedicated user (if not existing)
  53. ynh_system_user_create $app
  54. #=================================================
  55. # RESTORE USER RIGHTS
  56. #=================================================
  57. # Restore permissions on app files
  58. chown -R root: $final_path
  59. #=================================================
  60. # RESTORE THE PHP-FPM CONFIGURATION
  61. #=================================================
  62. ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
  63. #=================================================
  64. # SPECIFIC RESTORATION
  65. #=================================================
  66. # REINSTALL DEPENDENCIES
  67. #=================================================
  68. # Define and install dependencies
  69. ynh_install_app_dependencies deb1 deb2
  70. #=================================================
  71. # RESTORE SYSTEMD
  72. #=================================================
  73. ynh_restore_file "/etc/systemd/system/$app.service"
  74. systemctl enable $app.service
  75. #=================================================
  76. # ADVERTISE SERVICE IN ADMIN PANEL
  77. #=================================================
  78. yunohost service add $app --log "/var/log/$app/APP.log"
  79. #=================================================
  80. # RESTORE THE CRON FILE
  81. #=================================================
  82. ynh_restore_file "/etc/cron.d/$app"
  83. #=================================================
  84. # RESTORE THE LOGROTATE CONFIGURATION
  85. #=================================================
  86. ynh_restore_file "/etc/logrotate.d/$app"
  87. #=================================================
  88. # GENERIC FINALIZATION
  89. #=================================================
  90. # RELOAD NGINX AND PHP-FPM
  91. #=================================================
  92. systemctl reload php5-fpm
  93. systemctl reload nginx