upgrade 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/conf/zabbix.conf.php" ]; then
  38. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  39. fi
  40. ln -s "/etc/zabbix/web/zabbix.conf.php" "/usr/share/zabbix/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. if [ ! -d "/usr/share/zabbix-cli" ]; then
  46. zabbix_username="svc_${app}_ldap"
  47. zabbix_password=$(ynh_string_random --length=32)
  48. ynh_app_setting_set --app="$app" --key=zabbix_username --value="$zabbix_username"
  49. ynh_app_setting_set --app="$app" --key=zabbix_password --value="$zabbix_password"
  50. yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
  51. mkdir -p /usr/share/zabbix-cli
  52. python3 -m venv /usr/share/zabbix-cli
  53. /usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
  54. ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  55. enable_admin_user
  56. /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
  57. disable_admin_user
  58. ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
  59. fi
  60. #=================================================
  61. # SPECIFIC UPGRADE
  62. #=================================================
  63. # CUSTOMIZE DATABASE
  64. #=================================================
  65. ynh_script_progression --message="Customize the database..."
  66. convert_ZabbixDB
  67. set_mediatype_default_yunohost
  68. #=================================================
  69. # REAPPLY SYSTEM CONFIGURATIONS
  70. #=================================================
  71. ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
  72. # Create a dedicated PHP-FPM config
  73. ynh_add_fpm_config
  74. # Create a dedicated NGINX config
  75. ynh_add_nginx_config
  76. change_timeoutAgent
  77. systemctl enable zabbix-agent --quiet
  78. systemctl enable zabbix-server --quiet
  79. yunohost service add snmpd --description="Management of SNMP Daemon"
  80. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  81. 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"
  82. update_initZabbixConf
  83. #=================================================
  84. # START SYSTEMD SERVICE
  85. #=================================================
  86. ynh_script_progression --message="Starting $app's systemd service..." --weight=1
  87. # Start a systemd service
  88. ynh_systemd_action --service_name="$app-server" --action="restart" --log_path="/var/log/$app/${app}_server.log" --line_match="server #0 started"
  89. ynh_systemd_action --service_name="$app-agent" --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  90. #=================================================
  91. # END OF SCRIPT
  92. #=================================================
  93. ynh_script_progression --message="Upgrade of $app completed"