remove 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. app=$YNH_APP_INSTANCE_NAME
  13. #domain=$(ynh_app_setting_get "$app" domain) #not used
  14. port=$(ynh_app_setting_get "$app" port)
  15. db_name=$(ynh_app_setting_get "$app" db_name)
  16. db_user=$db_name
  17. #final_path=$(ynh_app_setting_get "$app" final_path) #not used
  18. #=================================================
  19. # REMOVE SERVICE FROM ADMIN PANEL
  20. #=================================================
  21. # Remove a service from the admin panel, added by `yunohost service add`
  22. yunohost service remove snmpd
  23. yunohost service remove zabbix-server
  24. yunohost service remove zabbix-agent
  25. #=================================================
  26. # REMOVE PHP-FPM CONFIGURATION
  27. #=================================================
  28. # Remove the dedicated php-fpm config
  29. ynh_remove_fpm_config
  30. systemctl reload php7.0-fpm
  31. #=================================================
  32. # REMOVE DEPENDENCIES
  33. #=================================================
  34. timeout 5 systemctl stop zabbix-server || killall zabbix_server
  35. systemctl disable zabbix-server
  36. killall zabbix_server
  37. timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd
  38. systemctl disable zabbix-agent
  39. killall zabbix_agentd
  40. ynh_remove_app_dependencies
  41. #remove symlink
  42. rm /var/www/zabbix
  43. #=================================================
  44. # REMOVE THE MYSQL DATABASE
  45. #=================================================
  46. # Remove a database if it exists, along with the associated user
  47. ynh_mysql_remove_db "$db_user" "$db_name"
  48. #=================================================
  49. # REMOVE NGINX CONFIGURATION
  50. #=================================================
  51. # Remove the dedicated nginx config
  52. ynh_remove_nginx_config
  53. #=================================================
  54. # RELOAD NGINX
  55. #=================================================
  56. systemctl reload nginx
  57. #=================================================
  58. # REMOVE LOGROTATE CONFIGURATION
  59. #=================================================
  60. # Remove the app-specific logrotate config
  61. ynh_remove_logrotate
  62. #=================================================
  63. # CLOSE A PORT
  64. #=================================================
  65. if yunohost firewall list | grep -q "\- $port$"
  66. then
  67. echo "Close port $port" >&2
  68. yunohost firewall disallow TCP "$port" 2>&1
  69. fi
  70. #=================================================
  71. # SPECIFIC REMOVE
  72. #=================================================
  73. # REMOVE THE CRON FILE
  74. #=================================================
  75. # Remove a directory securely
  76. ynh_secure_remove "/etc/zabbix"
  77. # Remove the log files
  78. ynh_secure_remove "/var/log/zabbix"
  79. # Remove the pid/socket files
  80. ynh_secure_remove "/run/zabbix"
  81. # Remove the sudoers file
  82. ynh_secure_remove "/etc/sudoers.d/zabbix"
  83. #REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
  84. nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
  85. if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then
  86. ynh_print_info "Removing snmp-mibs-downloader (non-free package)"
  87. sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status
  88. DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
  89. if [ -f /etc/apt/sources.list.d/non-free.list ];then
  90. ynh_secure_remove /etc/apt/sources.list.d/non-free.list
  91. fi
  92. fi
  93. #=================================================
  94. # GENERIC FINALIZATION
  95. #=================================================
  96. # REMOVE DEDICATED USER
  97. #=================================================
  98. # Delete a system user
  99. ynh_system_user_delete zabbix