restore 3.7 KB

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