Best practices for pre-uninstall tasks?

Hi all,

I know that the remove hook exists. Is there a best practice for performing tasks that need to run when the snap is being removed from a system, but before services have been shut down?

The specific case I have in mind is in MicroStack. It leaves an Open vSwitch bridge device behind. The bridge goes away on reboot, but I still want to be as tidy as possible when tearing the snap down, especially in the case where an operator might be uninstalling, then reinstalling the snap in a test environment or in preparation for a demo.

The correct command to remove the bridge is microstack.ovsctl delbr br-ex. But that command only works while the Open vSwitch daemon is running. And it isn’t running by the time snapd executes the remove hook!

I’m thinking of simply writing and documenting a microstack.uninstall script. But I’m curious as to whether there is something that integrates more neatly with the built in snap remove microstack invocation.

Hey @petevg,

Shouldn’t it also clean up on, say, snap stop microstack? In which case, it sounds like a service shutdown task rather than a remove hook?

@Saviq That’s a good point. I’ve been focused on making sure the bridge persists (e.g., gets recreated on reboot) while MicroStack is installed. It would definitely be more polite to simply remove it when Open vSwitch services come down.