upgrade 5.3 KB

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