restore 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC STARTING
  4. #=================================================
  5. # MANAGE FAILURE OF THE SCRIPT
  6. #=================================================
  7. # Exit on command errors and treat unset variables as an error
  8. set -eu
  9. #=================================================
  10. # IMPORT GENERIC HELPERS
  11. #=================================================
  12. source /usr/share/yunohost/helpers
  13. #=================================================
  14. # LOAD SETTINGS
  15. #=================================================
  16. app=$YNH_APP_INSTANCE_NAME
  17. domain=$(ynh_app_setting_get $app domain)
  18. path_url=$(ynh_app_setting_get $app path)
  19. final_path=$(ynh_app_setting_get $app final_path)
  20. db_name=$(ynh_app_setting_get $app db_name)
  21. #=================================================
  22. # CHECK IF THE APP CAN BE RESTORED
  23. #=================================================
  24. sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
  25. || ynh_die "Path not available: ${domain}${path_url}"
  26. test ! -d $final_path \
  27. || ynh_die "There is already a directory: $final_path "
  28. #=================================================
  29. # STANDARD RESTORE STEPS
  30. #=================================================
  31. # RESTORE OF THE NGINX CONFIGURATION
  32. #=================================================
  33. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  34. #=================================================
  35. # RESTORE OF THE MAIN DIR OF THE APP
  36. #=================================================
  37. ynh_restore_file "$final_path"
  38. #=================================================
  39. # RESTORE OF THE SQL BDD
  40. #=================================================
  41. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  42. ynh_mysql_setup_db $db_name $db_name $db_pwd
  43. ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
  44. #=================================================
  45. # RECREATE OF THE DEDICATED USER
  46. #=================================================
  47. # Recreate the dedicated user, if not exist
  48. ynh_system_user_create $app
  49. #=================================================
  50. # RESTORE USER RIGHTS
  51. #=================================================
  52. # Restore permissions to app files
  53. sudo chown -R root: $final_path
  54. #=================================================
  55. # RESTORE OF THE PHP-FPM CONFIGURATION
  56. #=================================================
  57. ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
  58. ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
  59. #=================================================
  60. # SPECIFIC RESTORE
  61. #=================================================
  62. # REINSTALL DEPENDENCIES
  63. #=================================================
  64. # Define and install dependencies with a equivs control file
  65. ynh_install_app_dependencies deb1 deb2
  66. #=================================================
  67. # ENABLE SERVICE IN ADMIN PANEL
  68. #=================================================
  69. sudo yunohost service add $app --log "/var/log/$app/APP.log"
  70. #=================================================
  71. # RESTORE SYSTEMD
  72. #=================================================
  73. ynh_restore_file "/etc/systemd/system/$app.service"
  74. sudo systemctl enable $app.service
  75. #=================================================
  76. # RESTORE OF THE CRON FILE
  77. #=================================================
  78. ynh_restore_file "/etc/cron.d/$app"
  79. #=================================================
  80. # BACKUP OF THE LOGROTATE CONFIGURATION
  81. #=================================================
  82. ynh_restore_file "/etc/logrotate.d/$app"
  83. #=================================================
  84. # GENERIC FINALISATION
  85. #=================================================
  86. # RELOAD NGINX AND PHP-FPM
  87. #=================================================
  88. sudo systemctl reload php5-fpm
  89. sudo systemctl reload nginx