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