restore 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. rm -fr $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. wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb"
  46. dpkg -i zabbix-release_*.deb
  47. rm zabbix-release_*.deb
  48. ynh_print_info "Update and install dependencies"
  49. ynh_package_update
  50. ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq zabbix-server-mysql zabbix-agent zabbix-frontend-php
  51. DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php
  52. sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen
  53. locale-gen
  54. ln -s /usr/share/zabbix /var/www/zabbix
  55. rm $final_path/conf/zabbix.conf.php
  56. ynh_app_setting_set $app final_path $final_path
  57. #=================================================
  58. # NGINX CONFIGURATION
  59. #=================================================
  60. ### `ynh_add_nginx_config` will use the file conf/nginx.conf
  61. # Create a dedicated nginx config
  62. ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
  63. #=================================================
  64. # PHP-FPM CONFIGURATION
  65. #=================================================
  66. ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf"
  67. # Restore sudo file
  68. ynh_restore_file "/etc/sudoers.d/zabbix"
  69. #=================================================
  70. # Restore db
  71. #=================================================
  72. db_name=$(ynh_app_setting_get $app db_name)
  73. db_user=$(ynh_app_setting_get $app db_user)
  74. db_pwd=$(ynh_app_setting_get $app mysqlpwd)
  75. ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
  76. ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql
  77. #=================================================
  78. # Restore configs files
  79. #=================================================
  80. ### `ynh_replace_string` is used to replace a string in a file.
  81. ### (It's compatible with sed regular expressions syntax)
  82. ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
  83. chown -R www-data. /usr/share/zabbix
  84. ynh_restore_file "/etc/zabbix"
  85. # systemd and yunohost service management
  86. systemctl enable zabbix-server && systemctl start zabbix-server
  87. yunohost service add snmpd -d "Management of SNMP Daemon"
  88. yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify"
  89. yunohost service add zabbix-client -d "Management Zabbix client daemon : send informations about this host to the server"
  90. #=================================================
  91. # SETUP LOGROTATE
  92. #=================================================
  93. ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app.
  94. ### Use this helper only if there is effectively a log file for this app.
  95. ### If you're not using this helper:
  96. ### - Remove the section "BACKUP LOGROTATE" in the backup script
  97. ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script
  98. ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script
  99. ### - And the section "SETUP LOGROTATE" in the upgrade script
  100. # Use logrotate to manage application logfile(s)
  101. #ynh_use_logrotate
  102. #no need, use native logrotate in zabbix packages
  103. #=================================================
  104. # SETUP SSOWAT
  105. #=================================================
  106. # Make app public if necessary
  107. if [ "$is_public" -eq 1 ]
  108. then
  109. # unprotected_uris allows SSO credentials to be passed anyway.
  110. ynh_app_setting_set $app unprotected_uris "/"
  111. fi
  112. #=================================================
  113. # RELOAD NGINX
  114. #=================================================
  115. systemctl reload nginx
  116. systemctl reload php7.0-fpm
  117. # Reload SSOwat config
  118. yunohost app ssowatconf
  119. #test if zabbix server is started
  120. check_proc_zabbixagent
  121. #test if zabbix agent is started
  122. check_proc_zabbixserver