restore 6.7 KB

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