upgrade 6.3 KB

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