restore 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
  8. source ../settings/scripts/_common.sh
  9. source /usr/share/yunohost/helpers
  10. #=================================================
  11. # MANAGE SCRIPT FAILURE
  12. #=================================================
  13. # Exit if an error occurs during the execution of the script
  14. ynh_abort_if_errors
  15. #=================================================
  16. # LOAD SETTINGS
  17. #=================================================
  18. ynh_script_progression --message="Loading installation settings..."
  19. app=$YNH_APP_INSTANCE_NAME
  20. domain=$(ynh_app_setting_get $app --key=domain)
  21. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  22. is_public=$(ynh_app_setting_get --app=$app --key=is_public)
  23. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  24. db_user=$db_name
  25. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  26. #=================================================
  27. # CHECK IF THE APP CAN BE RESTORED
  28. #=================================================
  29. ynh_script_progression --message="Validating restoration parameters..."
  30. ynh_secure_remove --file="$final_path"
  31. #=================================================
  32. # STANDARD RESTORATION STEPS
  33. #=================================================
  34. # RESTORE THE NGINX CONFIGURATION
  35. #=================================================
  36. ynh_script_progression --message="Restoring the NGINX web server configuration..."
  37. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  38. #=================================================
  39. # RESTORE THE APP MAIN DIR
  40. #=================================================
  41. ynh_script_progression --message="Restoring the app main directory..."
  42. ln -s /usr/share/zabbix "$final_path"
  43. chmod 750 "$final_path"
  44. chmod -R o-rwx "$final_path"
  45. chown -R $app:www-data "$final_path"
  46. #=================================================
  47. # RESTORE THE PHP-FPM CONFIGURATION
  48. #=================================================
  49. ynh_script_progression --message="Restoring the PHP-FPM configuration..."
  50. ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
  51. #=================================================
  52. # SPECIFIC RESTORATION
  53. #=================================================
  54. # REINSTALL DEPENDENCIES
  55. #=================================================
  56. ynh_script_progression --message="Reinstalling dependencies..."
  57. install_zabbix_repo
  58. ynh_package_update
  59. ynh_install_app_dependencies $pkg_dependencies
  60. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  61. ynh_replace_string --match_string="# fr_FR.UTF-8 UTF-8" --replace_string="fr_FR.UTF-8 UTF-8" --target_file=/etc/locale.gen
  62. locale-gen
  63. #=================================================
  64. # RESTORE THE MYSQL DATABASE
  65. #=================================================
  66. ynh_script_progression --message="Restoring the MySQL database..."
  67. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  68. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
  69. ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
  70. convert_ZabbixDB
  71. #=================================================
  72. # RESTORE VARIOUS FILES
  73. #=================================================
  74. ynh_script_progression --message="Restoring various files..."
  75. # Restore frontend config
  76. ynh_restore_file --origin_path="$final_path/conf/zabbix.conf.php"
  77. chown -R www-data. /usr/share/zabbix
  78. ynh_restore_file --origin_path="/etc/zabbix"
  79. ls -Rail "/etc/zabbix"
  80. ynh_restore_file --origin_path="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
  81. # Restore server config
  82. ynh_restore_file --origin_path="/etc/zabbix/zabbix_server.conf"
  83. # Restore agent config
  84. ynh_restore_file --origin_path="/etc/zabbix/zabbix_agentd.conf"
  85. if [ ! -L /etc/zabbix/zabbix_agentd.d ];then
  86. ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
  87. fi
  88. # Restore sudo file
  89. ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
  90. #=================================================
  91. # INTEGRATE SERVICE IN YUNOHOST
  92. #=================================================
  93. ynh_script_progression --message="Integrating service in YunoHost..."
  94. yunohost service add snmpd --description="Management of SNMP Daemon"
  95. yunohost service add zabbix-server --description="Management Zabbix server daemon : Collect, agregate, compute and notify"
  96. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server"
  97. #=================================================
  98. # START SYSTEMD SERVICE
  99. #=================================================
  100. ynh_script_progression --message="Starting a systemd service..."
  101. systemctl enable --quiet zabbix-agent && systemctl restart zabbix-agent
  102. change_timeoutAgent
  103. systemctl enable --quiet zabbix-server && systemctl restart zabbix-server
  104. #test if zabbix server is started
  105. check_proc_zabbixagent
  106. #test if zabbix agent is started
  107. check_proc_zabbixserver
  108. #=================================================
  109. # GENERIC FINALIZATION
  110. #=================================================
  111. # RELOAD NGINX AND PHP-FPM
  112. #=================================================
  113. ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
  114. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  115. ynh_systemd_action --service_name=nginx --action=reload
  116. #=================================================
  117. # END OF SCRIPT
  118. #=================================================
  119. ynh_script_progression --message="Restoration completed for $app"