restore 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. ### If it's a multi-instance app, meaning it can be installed several times independently
  15. ### The id of the app as stated in the manifest is available as $YNH_APP_ID
  16. ### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
  17. ### The app instance name is available as $YNH_APP_INSTANCE_NAME
  18. ### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
  19. ### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
  20. ### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
  21. ### The app instance name is probably what interests you most, since this is
  22. ### guaranteed to be unique. This is a good unique identifier to define installation path,
  23. ### db names, ...
  24. app="zabbix"
  25. final_path="/var/www/zabbix"
  26. #=================================================
  27. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  28. #=================================================
  29. ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
  30. ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
  31. ynh_secure_remove $final_path
  32. #=================================================
  33. # STORE SETTINGS FROM MANIFEST
  34. #=================================================
  35. domain=$(ynh_app_setting_get $app domain)
  36. #path_url=$(ynh_app_setting_get $app path) #not used
  37. #admin=$(ynh_app_setting_get $app admin) #not used
  38. is_public=$(ynh_app_setting_get $app is_public)
  39. #language=$(ynh_app_setting_get $app language) #not used
  40. nonfree=$(ynh_app_setting_get $app nonfree)
  41. #=================================================
  42. # INSTALL DEPENDENCIES
  43. #=================================================
  44. ynh_print_info "Install Zabbix repository"
  45. install_zabbix_repo
  46. ynh_print_info "Update and install dependencies"
  47. ynh_package_update
  48. ynh_install_app_dependencies $pkg_dependencies
  49. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  50. ynh_replace_string --match_string="# fr_FR.UTF-8 UTF-8" --replace_string="fr_FR.UTF-8 UTF-8" --target_file=/etc/locale.gen
  51. locale-gen
  52. ln -s /usr/share/zabbix /var/www/zabbix
  53. ynh_secure_remove $final_path/conf/zabbix.conf.php
  54. ynh_app_setting_set $app final_path $final_path
  55. #=================================================
  56. # NGINX CONFIGURATION
  57. #=================================================
  58. ### `ynh_add_nginx_config` will use the file conf/nginx.conf
  59. # Create a dedicated nginx config
  60. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  61. #=================================================
  62. # PHP-FPM CONFIGURATION
  63. #=================================================
  64. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  65. # Restore sudo file
  66. ynh_restore_file "/etc/sudoers.d/zabbix"
  67. #=================================================
  68. # Restore db
  69. #=================================================
  70. db_name=$(ynh_app_setting_get $app db_name)
  71. db_user=$(ynh_app_setting_get $app db_user)
  72. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  73. ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
  74. convert_ZabbixDB
  75. ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql
  76. #=================================================
  77. # Restore configs files
  78. #=================================================
  79. ### `ynh_replace_string` is used to replace a string in a file.
  80. ### (It's compatible with sed regular expressions syntax)
  81. ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
  82. chown -R www-data. /usr/share/zabbix
  83. ynh_restore_file "/etc/zabbix"
  84. ls -Rail "/etc/zabbix"
  85. #ynh_restore_file "/etc/zabbix/web"
  86. #ynh_restore_file "/etc/zabbix/web/init.zabbix.conf.php.sh"
  87. ynh_restore_file "/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
  88. if [ ! -L /etc/zabbix/zabbix_agentd.d ];then
  89. ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
  90. fi
  91. systemctl enable --quiet zabbix-agent && systemctl restart zabbix-agent
  92. change_timeoutAgent
  93. systemctl enable --quiet zabbix-server && systemctl restart zabbix-server
  94. yunohost service add snmpd -d "Management of SNMP Daemon"
  95. yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify"
  96. yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server"
  97. #=================================================
  98. # SETUP LOGROTATE
  99. #=================================================
  100. ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
  101. ### Use this helper only if there is effectively a log file for this app.
  102. ### If you're not using this helper:
  103. ### - Remove the section "BACKUP LOGROTATE" in the backup script
  104. ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
  105. ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
  106. ### - And the section "SETUP LOGROTATE" in the upgrade script
  107. # Use logrotate to manage application logfile(s)
  108. #ynh_use_logrotate
  109. #no need, use native logrotate in zabbix packages
  110. #=================================================
  111. # SETUP SSOWAT
  112. #=================================================
  113. # Make app public if necessary
  114. if [ "$is_public" -eq 1 ]
  115. then
  116. # unprotected_uris allows SSO credentials to be passed anyway.
  117. ynh_app_setting_set $app unprotected_uris "/"
  118. fi
  119. #=================================================
  120. # RELOAD NGINX
  121. #=================================================
  122. systemctl reload nginx
  123. systemctl reload php7.0-fpm
  124. # Reload SSOwat config
  125. yunohost app ssowatconf
  126. #test if zabbix server is started
  127. check_proc_zabbixagent
  128. #test if zabbix agent is started
  129. check_proc_zabbixserver