remove 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. port=$(ynh_app_setting_get --app=$app --key=port)
  16. db_name=$(ynh_app_setting_get --app=$app --key=db_name)
  17. db_user=$db_name
  18. #=================================================
  19. # STANDARD REMOVE
  20. #=================================================
  21. # REMOVE SERVICE INTEGRATION IN YUNOHOST
  22. #=================================================
  23. # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
  24. yunohost service remove snmpd
  25. yunohost service remove zabbix-server
  26. yunohost service remove zabbix-agent
  27. #=================================================
  28. # STOP AND REMOVE SERVICE
  29. #=================================================
  30. ynh_script_progression --message="Stopping and removing the systemd service..."
  31. # Remove the dedicated systemd config
  32. timeout 5 systemctl stop zabbix-server || killall zabbix-server
  33. systemctl disable zabbix-server --quiet
  34. killall zabbix-server
  35. timeout 5 systemctl stop zabbix-agent || killall zabbix-agentd
  36. systemctl disable zabbix-agent --quiet
  37. killall zabbix-agentd
  38. #=================================================
  39. # REMOVE THE MYSQL DATABASE
  40. #=================================================
  41. ynh_script_progression --message="Removing the MySQL database..."
  42. # Remove a database if it exists, along with the associated user
  43. ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
  44. #=================================================
  45. # REMOVE DEPENDENCIES
  46. #=================================================
  47. ynh_script_progression --message="Removing dependencies..."
  48. # Remove config file detection
  49. delete_initZabbixConf
  50. DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
  51. # Remove metapackage and its dependencies
  52. ynh_remove_app_dependencies
  53. # Force removing if ynh_remove_app_dependencies not work (old zabbix version)
  54. for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)")
  55. do
  56. DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y
  57. done
  58. remove_zabbix_repo
  59. #=================================================
  60. # REMOVE APP MAIN DIR
  61. #=================================================
  62. ynh_script_progression --message="Removing app main directory..."
  63. # Remove the app directory securely
  64. ynh_secure_remove --file="$final_path"
  65. #=================================================
  66. # REMOVE NGINX CONFIGURATION
  67. #=================================================
  68. ynh_script_progression --message="Removing NGINX web server configuration..."
  69. # Remove the dedicated NGINX config
  70. ynh_remove_nginx_config
  71. #=================================================
  72. # REMOVE PHP-FPM CONFIGURATION
  73. #=================================================
  74. ynh_script_progression --message="Removing PHP-FPM configuration..."
  75. # Remove the dedicated PHP-FPM config
  76. ynh_remove_fpm_config
  77. #=================================================
  78. # SPECIFIC REMOVE
  79. #=================================================
  80. # REMOVE VARIOUS FILES
  81. #=================================================
  82. ynh_script_progression --message="Removing various files..."
  83. # Remove a directory securely
  84. if [ -d /etc/zabbix ] ;then ynh_secure_remove --file="/etc/$app";fi
  85. # Remove the log files
  86. if [ -d /var/log/zabbix ] ;then ynh_secure_remove --file="/var/log/$app";fi
  87. # Remove the pid/socket files
  88. if [ -d /run/zabbix ] ;then ynh_secure_remove --file="/run/zabbix";fi
  89. # Remove the sudoers file
  90. if [ -f /etc/sudoers.d/zabbix ] ;then ynh_secure_remove --file="/etc/sudoers.d/zabbix";fi
  91. #=================================================
  92. # GENERIC FINALIZATION
  93. #=================================================
  94. # REMOVE DEDICATED USER
  95. #=================================================
  96. ynh_script_progression --message="Removing the dedicated system user..."
  97. # Delete a system user
  98. ynh_system_user_delete --username=$app
  99. #=================================================
  100. # END OF SCRIPT
  101. #=================================================
  102. ynh_script_progression --message="Removal of $app completed"