upgrade 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # LOAD SETTINGS
  11. #=================================================
  12. ynh_script_progression --message="Loading installation settings..."
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get --app=$app --key=domain)
  15. path_url=$(ynh_app_setting_get --app=$app --key=path)
  16. language=$(ynh_app_setting_get --app=$app --key=language)
  17. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  18. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  19. db_user=$db_name
  20. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  21. trustedversion="5.0.0-1+stretch"
  22. #=================================================
  23. # CHECK VERSION
  24. #=================================================
  25. ynh_script_progression --message="Checking version..."
  26. upgrade_type=$(ynh_check_app_version_changed)
  27. #=================================================
  28. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  29. #=================================================
  30. ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
  31. # Backup the current version of the app
  32. ynh_backup_before_upgrade
  33. ynh_clean_setup () {
  34. ynh_clean_check_starting
  35. # Restore it if the upgrade fails
  36. ynh_restore_upgradebackup
  37. }
  38. # Exit if an error occurs during the execution of the script
  39. ynh_abort_if_errors
  40. #=================================================
  41. # STANDARD UPGRADE STEPS
  42. #=================================================
  43. # STOP SYSTEMD SERVICE
  44. #=================================================
  45. ynh_script_progression --message="Stopping a systemd service..."
  46. ynh_systemd_action --service_name=$app-server --action="stop" --log_path="/var/log/$app/${app}_server.log"
  47. ynh_systemd_action --service_name=$app-agent --action="stop" --log_path="/var/log/$app/${app}_agent.log"
  48. #=================================================
  49. # ENSURE DOWNWARD COMPATIBILITY
  50. #=================================================
  51. ynh_script_progression --message="Ensuring downward compatibility..."
  52. # If db_name doesn't exist, create it
  53. if [ -z "$db_name" ]; then
  54. db_name=$(ynh_sanitize_dbid --db_name=$app)
  55. ynh_app_setting_set --app=$app --key=db_name --value=$db_name
  56. fi
  57. # If final_path doesn't exist, create it
  58. if [ -z "$final_path" ]; then
  59. final_path=/var/www/$app
  60. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  61. fi
  62. if [ "$language" == "fr" ]
  63. then
  64. language="fr_FR"
  65. ynh_app_setting_set --app=$app --key=language --value=$language
  66. fi
  67. if [ "$language" == "en" ]
  68. then
  69. language="en_GB"
  70. ynh_app_setting_set --app=$app --key=language --value=$language
  71. fi
  72. export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
  73. # patch to remove old zabbix-client service
  74. if [ ! -z "$(yunohost service status | grep zabbix-client)" ]
  75. then
  76. ynh_script_progression --message="remove zabbix-client old service"
  77. yunohost service remove zabbix-client
  78. fi
  79. ynh_remove_logrotate
  80. # Check if new zabbix version is available on repo"
  81. ynh_package_update
  82. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  83. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  84. chown $app:www-data "/etc/zabbix/web/zabbix.conf.php"
  85. if [ -f "/usr/share/zabbix/conf/zabbix.conf.php" ]
  86. then
  87. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  88. fi
  89. ln -s "/etc/zabbix/web/zabbix.conf.php" "/usr/share/zabbix/conf/zabbix.conf.php"
  90. ynh_remove_extra_repo --name=zabbix
  91. #=================================================
  92. # UPGRADE DEPENDENCIES
  93. #=================================================
  94. if [ "$upgrade_type" == "UPGRADE_APP" ]
  95. then
  96. ynh_script_progression --message="Upgrading dependencies..."
  97. ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
  98. ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="http://repo.zabbix.com/zabbix/5.0/debian $(lsb_release -sc) main" --package="$zabbix_pkg_dependencies" --key="https://repo.zabbix.com/zabbix-official-repo.key"
  99. fi
  100. chmod 750 "/usr/share/zabbix"
  101. chmod -R o-rwx "/usr/share/zabbix"
  102. chown -R $app:www-data "/usr/share/zabbix"
  103. #=================================================
  104. # PHP-FPM CONFIGURATION
  105. #=================================================
  106. ynh_script_progression --message="Upgrading PHP-FPM configuration..."
  107. # Create a dedicated PHP-FPM config
  108. ynh_add_fpm_config
  109. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  110. #=================================================
  111. # NGINX CONFIGURATION
  112. #=================================================
  113. ynh_script_progression --message="Upgrading NGINX web server configuration..."
  114. # Create a dedicated NGINX config
  115. ynh_add_nginx_config
  116. #=================================================
  117. # SPECIFIC UPGRADE
  118. #=================================================
  119. # CUSTOMIZE DATABASE
  120. #=================================================
  121. ynh_script_progression --message="Customize the database..."
  122. convert_ZabbixDB
  123. set_mediatype_default_yunohost
  124. #=================================================
  125. # SETUP SYSTEMD
  126. #=================================================
  127. ynh_script_progression --message="Upgrading systemd configuration..."
  128. change_timeoutAgent
  129. systemctl enable zabbix-agent --quiet
  130. systemctl enable zabbix-server --quiet
  131. update_initZabbixConf
  132. #=================================================
  133. # GENERIC FINALIZATION
  134. #=================================================
  135. # INTEGRATE SERVICE IN YUNOHOST
  136. #=================================================
  137. ynh_script_progression --message="Integrating service in YunoHost..."
  138. yunohost service add snmpd --description="Management of SNMP Daemon"
  139. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  140. 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"
  141. #=================================================
  142. # START SYSTEMD SERVICE
  143. #=================================================
  144. ynh_script_progression --message="Starting a systemd service..."
  145. # Start a systemd service
  146. ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log" --line_match="server #0 started"
  147. ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  148. #=================================================
  149. # RELOAD NGINX
  150. #=================================================
  151. ynh_script_progression --message="Reloading NGINX web server..."
  152. ynh_systemd_action --service_name=nginx --action=reload
  153. #=================================================
  154. # END OF SCRIPT
  155. #=================================================
  156. ynh_script_progression --message="Upgrade of $app completed"