upgrade 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  17. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  18. db_user=$(ynh_app_setting_get --app=$app --key=db_user)
  19. db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
  20. language=$(ynh_app_setting_get --app=$app --key=language)
  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 if zabbix-release installed
  74. if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ]
  75. then
  76. DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y
  77. install_zabbix_repo
  78. fi
  79. # patch if zabbix-release has Candidate version but no Installed version
  80. if [ -f "/etc/apt/sources.list.d/zabbix.list" ]
  81. then
  82. if [ "$(grep -c "4.2" /etc/apt/sources.list.d/zabbix.list)" -eq 1 ]
  83. then
  84. install_zabbix_repo
  85. upgrade_type="UPGRADE_APP"
  86. fi
  87. fi
  88. # patch to remove old zabbix-client service
  89. if [ ! -z "$(yunohost service status | grep zabbix-client)" ]
  90. then
  91. ynh_script_progression --message="remove zabbix-client old service"
  92. yunohost service remove zabbix-client
  93. fi
  94. ynh_remove_logrotate
  95. # Check if new zabbix version is available on repo"
  96. ynh_package_update
  97. zabbixReleaseInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".* \K(.*)")
  98. if [[ "$trustedversion" > "$zabbixReleaseInstalledVersion" ]]
  99. then
  100. upgrade_type="UPGRADE_APP"
  101. fi
  102. if [ -f "/etc/zabbix/web/zabbix.conf.php" ]
  103. then
  104. ynh_secure_remove --file="/etc/zabbix/web/zabbix.conf.php"
  105. fi
  106. ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
  107. chmod 400 "/etc/zabbix/web/zabbix.conf.php"
  108. chown $app:www-data "/etc/zabbix/web/zabbix.conf.php"
  109. if [ -f "/usr/share/zabbix/conf/zabbix.conf.php" ]
  110. then
  111. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  112. fi
  113. ln -s "/etc/zabbix/web/zabbix.conf.php" "/usr/share/zabbix/conf/zabbix.conf.php"
  114. #=================================================
  115. # NGINX CONFIGURATION
  116. #=================================================
  117. ynh_script_progression --message="Upgrading NGINX web server configuration..."
  118. # Create a dedicated NGINX config
  119. ynh_add_nginx_config
  120. #=================================================
  121. # UPGRADE DEPENDENCIES
  122. #=================================================
  123. if [ "$upgrade_type" == "UPGRADE_APP" ]
  124. then
  125. ynh_script_progression --message="Upgrading dependencies..."
  126. install_zabbix_repo
  127. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  128. ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
  129. apt-get upgrade -y --option Dpkg::Options::=--force-confdef --option Dpkg::Options::=--force-confold
  130. fi
  131. #=================================================
  132. # RESTORE THE APP MAIN DIR
  133. #=================================================
  134. ynh_script_progression --message="Restoring the app main directory..."
  135. chmod 750 "/usr/share/zabbix"
  136. chmod -R o-rwx "/usr/share/zabbix"
  137. chown -R $app:www-data "/usr/share/zabbix"
  138. #=================================================
  139. # PHP-FPM CONFIGURATION
  140. #=================================================
  141. ynh_script_progression --message="Upgrading PHP-FPM configuration..."
  142. # Create a dedicated PHP-FPM config
  143. ynh_add_fpm_config --package="$extra_php_dependencies"
  144. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  145. #=================================================
  146. # SPECIFIC UPGRADE
  147. #=================================================
  148. # CUSTOMIZE DATABASE
  149. #=================================================
  150. ynh_script_progression --message="Customize the database..."
  151. convert_ZabbixDB
  152. set_mediatype_default_yunohost
  153. #=================================================
  154. # SETUP SYSTEMD
  155. #=================================================
  156. ynh_script_progression --message="Upgrading systemd configuration..."
  157. change_timeoutAgent
  158. systemctl enable zabbix-agent --quiet
  159. systemctl enable zabbix-server --quiet
  160. update_initZabbixConf
  161. #=================================================
  162. # GENERIC FINALIZATION
  163. #=================================================
  164. # INTEGRATE SERVICE IN YUNOHOST
  165. #=================================================
  166. ynh_script_progression --message="Integrating service in YunoHost..."
  167. yunohost service add snmpd --description="Management of SNMP Daemon"
  168. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  169. 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"
  170. #=================================================
  171. # START SYSTEMD SERVICE
  172. #=================================================
  173. ynh_script_progression --message="Starting a systemd service..."
  174. # Start a systemd service
  175. ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log" --line_match="server #0 started"
  176. ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  177. #=================================================
  178. # RELOAD NGINX
  179. #=================================================
  180. ynh_script_progression --message="Reloading NGINX web server..."
  181. ynh_systemd_action --service_name=nginx --action=reload
  182. #=================================================
  183. # END OF SCRIPT
  184. #=================================================
  185. ynh_script_progression --message="Upgrade of $app completed"