restore 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. if [ ! -e _common.sh ]; then
  8. # Get the _common.sh file if it's not in the current directory
  9. cp ../settings/scripts/_common.sh ./_common.sh
  10. chmod a+rx _common.sh
  11. fi
  12. source _common.sh
  13. source /usr/share/yunohost/helpers
  14. #=================================================
  15. # MANAGE SCRIPT FAILURE
  16. #=================================================
  17. ynh_clean_setup () {
  18. #### Remove this function if there's nothing to clean before calling the remove script.
  19. true
  20. }
  21. # Exit if an error occurs during the execution of the script
  22. ynh_abort_if_errors
  23. #=================================================
  24. # LOAD SETTINGS
  25. #=================================================
  26. app=$YNH_APP_INSTANCE_NAME
  27. domain=$(ynh_app_setting_get $app domain)
  28. path_url=$(ynh_app_setting_get $app path)
  29. final_path=$(ynh_app_setting_get $app final_path)
  30. db_name=$(ynh_app_setting_get $app db_name)
  31. #=================================================
  32. # CHECK IF THE APP CAN BE RESTORED
  33. #=================================================
  34. ynh_webpath_available $domain $path_url \
  35. || ynh_die "Path not available: ${domain}${path_url}"
  36. test ! -d $final_path \
  37. || ynh_die "There is already a directory: $final_path "
  38. #=================================================
  39. # STANDARD RESTORATION STEPS
  40. #=================================================
  41. # RESTORE THE NGINX CONFIGURATION
  42. #=================================================
  43. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  44. #=================================================
  45. # RESTORE THE APP MAIN DIR
  46. #=================================================
  47. ynh_restore_file "$final_path"
  48. #=================================================
  49. # RESTORE THE MYSQL DATABASE
  50. #=================================================
  51. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  52. ynh_mysql_setup_db $db_name $db_name $db_pwd
  53. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  54. #=================================================
  55. # RECREATE THE DEDICATED USER
  56. #=================================================
  57. # Create the dedicated user (if not existing)
  58. ynh_system_user_create $app
  59. #=================================================
  60. # RESTORE USER RIGHTS
  61. #=================================================
  62. # Restore permissions on app files
  63. chown -R root: $final_path
  64. #=================================================
  65. # RESTORE THE PHP-FPM CONFIGURATION
  66. #=================================================
  67. ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
  68. ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
  69. #=================================================
  70. # SPECIFIC RESTORATION
  71. #=================================================
  72. # REINSTALL DEPENDENCIES
  73. #=================================================
  74. # Define and install dependencies
  75. ynh_install_app_dependencies deb1 deb2
  76. #=================================================
  77. # ADVERTISE SERVICE IN ADMIN PANEL
  78. #=================================================
  79. yunohost service add $app --log "/var/log/$app/APP.log"
  80. #=================================================
  81. # RESTORE SYSTEMD
  82. #=================================================
  83. ynh_restore_file "/etc/systemd/system/$app.service"
  84. systemctl enable $app.service
  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. systemctl reload php5-fpm
  99. systemctl reload nginx