restore 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. ynh_clean_setup () {
  14. ynh_clean_check_starting
  15. }
  16. # Exit if an error occurs during the execution of the script
  17. ynh_abort_if_errors
  18. #=================================================
  19. # LOAD SETTINGS
  20. #=================================================
  21. ynh_script_progression --message="Loading installation settings..."
  22. app=$YNH_APP_INSTANCE_NAME
  23. domain=$(ynh_app_setting_get --app=$app --key=domain)
  24. path_url=$(ynh_app_setting_get --app=$app --key=path)
  25. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  26. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  27. db_user=$db_name
  28. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  29. language=$(ynh_app_setting_get --app=$app --key=language)
  30. #=================================================
  31. # CHECK IF THE APP CAN BE RESTORED
  32. #=================================================
  33. ynh_script_progression --message="Validating restoration parameters..."
  34. remove_previous_zabbix
  35. test ! -d $final_path \
  36. || ynh_die --message="There is already a directory: $final_path "
  37. #=================================================
  38. # STANDARD RESTORATION STEPS
  39. #=================================================
  40. # RESTORE THE NGINX CONFIGURATION
  41. #=================================================
  42. ynh_script_progression --message="Restoring the NGINX web server configuration..."
  43. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  44. #=================================================
  45. # SPECIFIC RESTORATION
  46. #=================================================
  47. # REINSTALL DEPENDENCIES
  48. #=================================================
  49. ynh_script_progression --message="Reinstalling dependencies..."
  50. # Define and install dependencies
  51. ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
  52. ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="http://repo.zabbix.com/zabbix/5.0/debian $(lsb_release -sc) main" --package="$zabbix_pkg_dependencies" --key="https://repo.zabbix.com/zabbix-official-repo.key"
  53. ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
  54. locale-gen
  55. #=================================================
  56. # RESTORE THE APP MAIN DIR
  57. #=================================================
  58. ynh_script_progression --message="Restoring the app main directory..."
  59. ln -s /usr/share/zabbix "$final_path"
  60. chmod 750 "/usr/share/zabbix"
  61. chmod -R o-rwx "/usr/share/zabbix"
  62. chown -R $app:www-data "/usr/share/zabbix"
  63. #=================================================
  64. # RESTORE THE PHP-FPM CONFIGURATION
  65. #=================================================
  66. ynh_script_progression --message="Restoring the PHP-FPM configuration..."
  67. # Restore the file first, so it can have a backup if different
  68. ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
  69. # Recreate a dedicated php-fpm config
  70. ynh_add_fpm_config --package="$extra_php_dependencies"
  71. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  72. #=================================================
  73. # RESTORE THE MYSQL DATABASE
  74. #=================================================
  75. ynh_script_progression --message="Restoring the MySQL database..."
  76. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  77. ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
  78. ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
  79. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  80. convert_ZabbixDB
  81. #=================================================
  82. # RESTORE VARIOUS FILES
  83. #=================================================
  84. ynh_script_progression --message="Restoring various files..."
  85. if [ -f "/etc/zabbix/web/zabbix.conf.php" ]
  86. then
  87. ynh_secure_remove --file="/etc/zabbix/web/zabbix.conf.php"
  88. fi
  89. ynh_restore_file --origin_path="/etc/zabbix/web/zabbix.conf.php"
  90. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  91. chown $app:www-data "/etc/zabbix/web/zabbix.conf.php"
  92. ynh_restore_file --origin_path="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
  93. ynh_restore_file --origin_path="/etc/zabbix/zabbix_server.conf"
  94. ynh_restore_file --origin_path="/etc/zabbix/zabbix_agentd.conf"
  95. if [ ! -L /etc/zabbix/zabbix_agentd.d ]
  96. then
  97. ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
  98. fi
  99. # Restore sudo file
  100. ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
  101. #=================================================
  102. # RESTORE SYSTEMD
  103. #=================================================
  104. ynh_script_progression --message="Restoring the systemd configuration..."
  105. change_timeoutAgent
  106. systemctl enable zabbix-agent --quiet
  107. systemctl enable zabbix-server --quiet
  108. #=================================================
  109. # INTEGRATE SERVICE IN YUNOHOST
  110. #=================================================
  111. ynh_script_progression --message="Integrating service in YunoHost..."
  112. yunohost service add snmpd --description="Management of SNMP Daemon"
  113. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  114. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server" --log="/var/log/$app/${app}_agent.log"
  115. #=================================================
  116. # START SYSTEMD SERVICE
  117. #=================================================
  118. ynh_script_progression --message="Starting a systemd service..."
  119. # Start a systemd service
  120. ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log"
  121. ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  122. #=================================================
  123. # GENERIC FINALIZATION
  124. #=================================================
  125. # RELOAD NGINX AND PHP-FPM
  126. #=================================================
  127. ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..."
  128. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  129. ynh_systemd_action --service_name=nginx --action=reload
  130. #=================================================
  131. # END OF SCRIPT
  132. #=================================================
  133. ynh_script_progression --message="Restoration completed for $app"