upgrade 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. #=================================================
  3. # IMPORT GENERIC HELPERS
  4. #=================================================
  5. source _common.sh
  6. source /usr/share/yunohost/helpers
  7. #=================================================
  8. # ENSURE DOWNWARD COMPATIBILITY
  9. #=================================================
  10. ynh_script_progression "Ensuring downward compatibility..."
  11. if ynh_compare_current_package_version --comparison lt --version 6.0~ynh2; then
  12. ynh_die --message="la version minimum requise pour cette version est la 6.0~ynh2, il n’est plus possible de faire une mise à jour/restauration de base de données depuis une version inférieure à la 6.0~ynh2 (commit 2ee2da0e3e8c95e90d78e234bcf2193869d115f8"
  13. fi
  14. #=================================================
  15. # STOP SYSTEMD SERVICE
  16. #=================================================
  17. ynh_script_progression --message="Stopping $app's systemd service..."
  18. ynh_systemd_action --service_name="$app-server" --action="stop" --log_path="/var/log/$app/${app}_server.log"
  19. ynh_systemd_action --service_name="$app-agent" --action="stop" --log_path="/var/log/$app/${app}_agent.log"
  20. #=================================================
  21. # ENSURE DOWNWARD COMPATIBILITY
  22. #=================================================
  23. ynh_script_progression --message="Ensuring downward compatibility..."
  24. if [ "$language" == "fr" ]; then
  25. language="fr_FR"
  26. ynh_app_setting_set --app="$app" --key="language" --value="$language"
  27. fi
  28. if [ "$language" == "en" ]; then
  29. language="en_GB"
  30. ynh_app_setting_set --app="$app" --key="language" --value="$language"
  31. fi
  32. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  33. # patch to remove old zabbix-client service
  34. if yunohost service status | grep zabbix-client; then
  35. ynh_script_progression --message="remove zabbix-client old service"
  36. yunohost service remove zabbix-client
  37. fi
  38. ynh_remove_logrotate
  39. # Check if new zabbix version is available on repo"
  40. ynh_package_update
  41. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  42. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  43. chown "$app:www-data" "/etc/zabbix/web/zabbix.conf.php"
  44. if [ -f "/usr/share/zabbix/conf/zabbix.conf.php" ]; then
  45. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  46. fi
  47. ln -s "/etc/zabbix/web/zabbix.conf.php" "/usr/share/zabbix/conf/zabbix.conf.php"
  48. ynh_remove_extra_repo --name=zabbix
  49. chmod 750 "/usr/share/zabbix"
  50. chmod -R o-rwx "/usr/share/zabbix"
  51. chown -R "$app:www-data" "/usr/share/zabbix"
  52. #=================================================
  53. # SPECIFIC UPGRADE
  54. #=================================================
  55. # CUSTOMIZE DATABASE
  56. #=================================================
  57. ynh_script_progression --message="Customize the database..."
  58. convert_ZabbixDB
  59. set_mediatype_default_yunohost
  60. #=================================================
  61. # REAPPLY SYSTEM CONFIGURATIONS
  62. #=================================================
  63. ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
  64. # Create a dedicated PHP-FPM config
  65. ynh_add_fpm_config
  66. # Create a dedicated NGINX config
  67. ynh_add_nginx_config
  68. change_timeoutAgent
  69. systemctl enable zabbix-agent --quiet
  70. systemctl enable zabbix-server --quiet
  71. yunohost service add snmpd --description="Management of SNMP Daemon"
  72. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  73. 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"
  74. update_initZabbixConf
  75. #=================================================
  76. # SETUP APPLICATION
  77. #=================================================
  78. ynh_script_progression --message="Setting up application..."
  79. if [ ! -d "/usr/share/zabbix-cli" ]; then
  80. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log" --line_match="server #0 started"
  81. zabbix_username="svc_${app}_ldap"
  82. zabbix_password=$(ynh_string_random --length=32)
  83. ynh_app_setting_set --app="$app" --key=zabbix_username --value="$zabbix_username"
  84. ynh_app_setting_set --app="$app" --key=zabbix_password --value="$zabbix_password"
  85. yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
  86. mkdir -p /usr/share/zabbix-cli
  87. python3 -m venv /usr/share/zabbix-cli
  88. /usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
  89. ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  90. enable_admin_user
  91. /usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $zabbix_username --firstname $zabbix_username --lastname $zabbix_username --passwd $zabbix_password --role superadmin --groups 7
  92. disable_admin_user
  93. ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  94. ynh_secure_remove --file="/usr/share/zabbix-cli/.zabbix-cli_auth_token"
  95. fi
  96. #import_template
  97. #link_template
  98. #=================================================
  99. # START SYSTEMD SERVICE
  100. #=================================================
  101. ynh_script_progression --message="Starting $app's systemd service..." --weight=1
  102. # Start a systemd service
  103. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log" --line_match="server #0 started"
  104. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  105. #=================================================
  106. # END OF SCRIPT
  107. #=================================================
  108. ynh_script_progression --message="Upgrade of $app completed"