restore 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
  64. #=================================================
  65. # SPECIFIC RESTORATION
  66. #=================================================
  67. # REINSTALL DEPENDENCIES
  68. #=================================================
  69. # Define and install dependencies
  70. ynh_install_app_dependencies deb1 deb2
  71. #=================================================
  72. # ADVERTISE SERVICE IN ADMIN PANEL
  73. #=================================================
  74. yunohost service add $app --log "/var/log/$app/APP.log"
  75. #=================================================
  76. # RESTORE SYSTEMD
  77. #=================================================
  78. ynh_restore_file "/etc/systemd/system/$app.service"
  79. systemctl enable $app.service
  80. #=================================================
  81. # RESTORE THE CRON FILE
  82. #=================================================
  83. ynh_restore_file "/etc/cron.d/$app"
  84. #=================================================
  85. # RESTORE THE LOGROTATE CONFIGURATION
  86. #=================================================
  87. ynh_restore_file "/etc/logrotate.d/$app"
  88. #=================================================
  89. # GENERIC FINALIZATION
  90. #=================================================
  91. # RELOAD NGINX AND PHP-FPM
  92. #=================================================
  93. systemctl reload php5-fpm
  94. systemctl reload nginx