upgrade 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. is_public=$(ynh_app_setting_get --app=$app --key=is_public)
  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. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  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. # Restore it if the upgrade fails
  35. ynh_restore_upgradebackup
  36. }
  37. # Exit if an error occurs during the execution of the script
  38. ynh_abort_if_errors
  39. #=================================================
  40. # STANDARD UPGRADE STEPS
  41. #=================================================
  42. # STOP SYSTEMD SERVICE
  43. #=================================================
  44. ynh_script_progression --message="Stopping a systemd service..."
  45. yunohost service stop zabbix-server
  46. yunohost service stop zabbix-agent
  47. #=================================================
  48. # ENSURE DOWNWARD COMPATIBILITY
  49. #=================================================
  50. ynh_script_progression --message="Ensuring downward compatibility..."
  51. export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
  52. disable_guest_user
  53. #Patch timeout too short for zabbix agent if needed
  54. change_timeoutAgent
  55. ynh_remove_logrotate
  56. # Cleaning legacy permissions
  57. if ynh_legacy_permissions_exists; then
  58. ynh_legacy_permissions_delete_all
  59. fi
  60. #=================================================
  61. # DOWNLOAD, CHECK AND UNPACK SOURCE
  62. #=================================================
  63. if [ "$upgrade_type" == "UPGRADE_APP" ]
  64. then
  65. ynh_script_progression --message="Upgrading source files..."
  66. # Download, check integrity, uncompress and patch the source from app.src
  67. ln -s /usr/share/zabbix "$final_path"
  68. fi
  69. #=================================================
  70. # NGINX CONFIGURATION
  71. #=================================================
  72. ynh_script_progression --message="Upgrading NGINX web server configuration..."
  73. # Create a dedicated NGINX config
  74. ynh_add_nginx_config
  75. #=================================================
  76. # UPGRADE DEPENDENCIES
  77. #=================================================
  78. ynh_script_progression --message="Upgrading dependencies..."
  79. if [ "$upgrade_type" == "UPGRADE_APP" ]
  80. then
  81. cp -rp /etc/zabbix /tmp/
  82. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  83. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  84. ynh_package_remove zabbix-server-mysql zabbix-frontend-php
  85. ynh_script_progression --message="Install Zabbix repository"
  86. install_zabbix_repo
  87. ynh_print_info "Update zabbix via apt package"
  88. ynh_install_app_dependencies $pkg_dependencies
  89. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  90. cp -rpf /tmp/zabbix /etc/
  91. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  92. ynh_secure_remove --file="/tmp/zabbix*"
  93. fi
  94. #=================================================
  95. # PHP-FPM CONFIGURATION
  96. #=================================================
  97. ynh_script_progression --message="Upgrading PHP-FPM configuration..."
  98. # Create a dedicated PHP-FPM config
  99. ynh_add_fpm_config --package="$extra_php_dependencies"
  100. #=================================================
  101. # SPECIFIC UPGRADE
  102. #=================================================
  103. # INSTALL hook to verify if conf file is broken (after an update for example)
  104. #=================================================
  105. update_initZabbixConf
  106. #=================================================
  107. # Update db to utf8
  108. #=================================================
  109. convert_ZabbixDB
  110. #=================================================
  111. # Add settings for yunohost mail server
  112. #=================================================
  113. set_mediatype_default_yunohost
  114. #=================================================
  115. # IMPORT YUNOHOST TEMPLATE
  116. #=================================================
  117. ynh_script_progression --message="Importing YunoHost template in Zabbix"
  118. import_template
  119. #=================================================
  120. # GENERIC FINALIZATION
  121. #=================================================
  122. # SETUP SSOWAT
  123. #=================================================
  124. ynh_script_progression --message="Configuring permissions..."
  125. # Make app public if necessary
  126. if [ $is_public -eq 1 ]
  127. then
  128. # Everyone can access the app.
  129. # The "main" permission is automatically created before the install script.
  130. ynh_permission_update --permission="main" --add="visitors"
  131. fi
  132. #=================================================
  133. # INTEGRATE SERVICE IN YUNOHOST
  134. #=================================================
  135. ynh_script_progression --message="Integrating service in YunoHost..."
  136. yunohost service add snmpd --description="Management of SNMP Daemon"
  137. yunohost service add zabbix-server --description="Management Zabbix server daemon : Collect, agregate, compute and notify"
  138. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server"
  139. #=================================================
  140. # START SYSTEMD SERVICE
  141. #=================================================
  142. ynh_script_progression --message="Starting a systemd service..."
  143. systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
  144. change_timeoutAgent
  145. systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
  146. #test if zabbix server is started
  147. check_proc_zabbixagent
  148. #test if zabbix agent is started
  149. check_proc_zabbixserver
  150. #=================================================
  151. # RELOAD NGINX
  152. #=================================================
  153. ynh_script_progression --message="Reloading NGINX web server..."
  154. ynh_systemd_action --service_name=nginx --action=reload
  155. #=================================================
  156. # END OF SCRIPT
  157. #=================================================
  158. ynh_script_progression --message="Upgrade of $app completed"