upgrade 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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=db_pwd)
  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. chmod 750 "$final_path"
  70. chmod -R o-rwx "$final_path"
  71. chown -R $app:www-data "$final_path"
  72. #=================================================
  73. # NGINX CONFIGURATION
  74. #=================================================
  75. ynh_script_progression --message="Upgrading NGINX web server configuration..."
  76. # Create a dedicated NGINX config
  77. ynh_add_nginx_config
  78. #=================================================
  79. # UPGRADE DEPENDENCIES
  80. #=================================================
  81. ynh_script_progression --message="Upgrading dependencies..."
  82. if [ "$upgrade_type" == "UPGRADE_APP" ]
  83. then
  84. cp -rp /etc/zabbix /tmp/
  85. cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
  86. DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
  87. ynh_package_remove zabbix-server-mysql zabbix-frontend-php
  88. ynh_script_progression --message="Install Zabbix repository"
  89. install_zabbix_repo
  90. ynh_print_info "Update zabbix via apt package"
  91. ynh_install_app_dependencies $pkg_dependencies
  92. ynh_secure_remove --file="/usr/share/zabbix/conf/zabbix.conf.php"
  93. cp -rpf /tmp/zabbix /etc/
  94. cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
  95. ynh_secure_remove --file="/tmp/zabbix*"
  96. fi
  97. #=================================================
  98. # PHP-FPM CONFIGURATION
  99. #=================================================
  100. ynh_script_progression --message="Upgrading PHP-FPM configuration..."
  101. # Create a dedicated PHP-FPM config
  102. ynh_add_fpm_config --package="$extra_php_dependencies"
  103. #=================================================
  104. # SPECIFIC UPGRADE
  105. #=================================================
  106. # INSTALL hook to verify if conf file is broken (after an update for example)
  107. #=================================================
  108. update_initZabbixConf
  109. #=================================================
  110. # Update db to utf8
  111. #=================================================
  112. convert_ZabbixDB
  113. #=================================================
  114. # Add settings for yunohost mail server
  115. #=================================================
  116. set_mediatype_default_yunohost
  117. #=================================================
  118. # IMPORT YUNOHOST TEMPLATE
  119. #=================================================
  120. ynh_script_progression --message="Importing YunoHost template in Zabbix"
  121. import_template
  122. #=================================================
  123. # GENERIC FINALIZATION
  124. #=================================================
  125. # SETUP SSOWAT
  126. #=================================================
  127. ynh_script_progression --message="Configuring permissions..."
  128. # Make app public if necessary
  129. if [ $is_public -eq 1 ]
  130. then
  131. # Everyone can access the app.
  132. # The "main" permission is automatically created before the install script.
  133. ynh_permission_update --permission="main" --add="visitors"
  134. fi
  135. #=================================================
  136. # INTEGRATE SERVICE IN YUNOHOST
  137. #=================================================
  138. ynh_script_progression --message="Integrating service in YunoHost..."
  139. yunohost service add snmpd --description="Management of SNMP Daemon"
  140. yunohost service add zabbix-server --description="Management Zabbix server daemon : Collect, agregate, compute and notify"
  141. yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server"
  142. #=================================================
  143. # START SYSTEMD SERVICE
  144. #=================================================
  145. ynh_script_progression --message="Starting a systemd service..."
  146. systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
  147. change_timeoutAgent
  148. systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
  149. #test if zabbix server is started
  150. check_proc_zabbixagent
  151. #test if zabbix agent is started
  152. check_proc_zabbixserver
  153. #=================================================
  154. # RELOAD NGINX
  155. #=================================================
  156. ynh_script_progression --message="Reloading NGINX web server..."
  157. ynh_systemd_action --service_name=nginx --action=reload
  158. #=================================================
  159. # END OF SCRIPT
  160. #=================================================
  161. ynh_script_progression --message="Upgrade of $app completed"