canonical / maas-anvil

A snap for managing charmed MAAS deployments.
https://maas.io
Apache License 2.0
3 stars 6 forks source link

Uninstall and cleanup #9

Open marosg42 opened 4 months ago

marosg42 commented 4 months ago

In the case when MAAS will be installed and reinstalled, sometimes with anvil, sometimes with snap or deb there needs to be a way how to cleanup and have environment ready for any other installation, so no leftovers prevent clean install with any of the possible methods.

There are basically two scenarios which needs to be covered

The second scenario will leave postgres snap installed on the machine, it would have mounted data for example

I ended up using combination of these commands

juju destroy-model admin/controller
sudo /usr/sbin/remove-juju-services
sudo umount /var/snap/charmed-postgresql/common
sudo umount /var/lib/snapd/snaps/charmed-postgresql_96.snap

for i in charmed-postgresql juju juju-db maas maas-anvil ; do sudo snap remove $i --purge ; done
rm -rf ~/.local/share/juju
sudo pkill haproxy

It would be great to have some script with smarts which would take care of both successful and failed installation.

marosg42 commented 2 months ago

Here is my big hammer temporary solution which seems to do the work. It is not nice at all but you may find some inspiration there

# timeout is set because I saw cases where it did not finish in 30 minutes and it was not progressing
ssh 10.244.40.30 "timeout 900 juju destroy-controller --destroy-all-models --destroy-storage --no-prompt anvil-controller"
for i in 30 31 32 ; do ssh 10.244.40.$i "sudo /usr/sbin/remove-juju-services" ; done
for i in 30 31 32 ; do ssh 10.244.40.$i "rm -rf .local/share/juju/" ; done
for i in 30 31 32 ; do ssh 10.244.40.$i "sudo snap stop charmed-postgresql" ; done
for i in 30 31 32 ; do ssh 10.244.40.$i "sudo umount /var/snap/charmed-postgresql/common; sudo umount /var/lib/snapd/snaps/charmed-postgresql_*.snap" ; done
for i in 30 31 32 ; do ssh 10.244.40.$i "for i in charmed-pgbouncer charmed-postgresql juju juju-db maas-anvil ; do sudo snap remove --purge \$i; done; sudo snap unalias patronictl"; done
for i in 30 31 32 ; do ssh 10.244.40.$i "sudo rm -rf /var/lib/juju" ; done