upgrade 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 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. # NGINX CONFIGURATION
  93. #=================================================
  94. ynh_script_progression --message="Upgrading NGINX web server configuration..."
  95. # Create a dedicated NGINX config
  96. ynh_add_nginx_config
  97. #=================================================
  98. # UPGRADE DEPENDENCIES
  99. #=================================================
  100. if [ "$upgrade_type" == "UPGRADE_APP" ]
  101. then
  102. ynh_script_progression --message="Upgrading dependencies..."
  103. ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
  104. 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"
  105. fi
  106. #=================================================
  107. # RESTORE THE APP MAIN DIR
  108. #=================================================
  109. ynh_script_progression --message="Restoring the app main directory..."
  110. chmod 750 "/usr/share/zabbix"
  111. chmod -R o-rwx "/usr/share/zabbix"
  112. chown -R $app:www-data "/usr/share/zabbix"
  113. #=================================================
  114. # PHP-FPM CONFIGURATION
  115. #=================================================
  116. ynh_script_progression --message="Upgrading PHP-FPM configuration..."
  117. # Create a dedicated PHP-FPM config
  118. ynh_add_fpm_config --package="$extra_php_dependencies"
  119. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  120. #=================================================
  121. # SPECIFIC UPGRADE
  122. #=================================================
  123. # CUSTOMIZE DATABASE
  124. #=================================================
  125. ynh_script_progression --message="Customize the database..."
  126. convert_ZabbixDB
  127. set_mediatype_default_yunohost
  128. #=================================================
  129. # SETUP SYSTEMD
  130. #=================================================
  131. ynh_script_progression --message="Upgrading systemd configuration..."
  132. change_timeoutAgent
  133. systemctl enable zabbix-agent --quiet
  134. systemctl enable zabbix-server --quiet
  135. update_initZabbixConf
  136. #=================================================
  137. # GENERIC FINALIZATION
  138. #=================================================
  139. # INTEGRATE SERVICE IN YUNOHOST
  140. #=================================================
  141. ynh_script_progression --message="Integrating service in YunoHost..."
  142. yunohost service add snmpd --description="Management of SNMP Daemon"
  143. yunohost service add zabbix-server --description="Management Zabbix server daemon : collect, agregate, compute and notify" --log="/var/log/$app/${app}_server.log"
  144. 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"
  145. #=================================================
  146. # START SYSTEMD SERVICE
  147. #=================================================
  148. ynh_script_progression --message="Starting a systemd service..."
  149. # Start a systemd service
  150. ynh_systemd_action --service_name=$app-server --action="restart" --log_path="/var/log/$app/${app}_server.log" --line_match="server #0 started"
  151. ynh_systemd_action --service_name=$app-agent --action="restart" --log_path="/var/log/$app/${app}_agent.log"
  152. #=================================================
  153. # RELOAD NGINX
  154. #=================================================
  155. ynh_script_progression --message="Reloading NGINX web server..."
  156. ynh_systemd_action --service_name=nginx --action=reload
  157. #=================================================
  158. # END OF SCRIPT
  159. #=================================================
  160. ynh_script_progression --message="Upgrade of $app completed"