Cleanup before services go down


The remove hook runs after any services provided by the snap are stopped. Is there a way to run some cleanup code before the services are down?

Consider this case, microk8s would like to stop all pods running before the services are stopped. Without this cleanup step docker related mountpoints are not released and the removal of the snap fails.


Shouldn’t this be done by the service when it gets a SIGTERM from systemd?

The services may be stopped only to be restarted again in the future. I shouldn’t clean the infrastructure in this case. Is there a way to know that the SIGTERM is caused by the snap being removed and not a stop/start systemd operation?

This would have to be a pre-remove hook or some such. That said, according to the docs on remove it runs before the last revision is removed? It explicitly mentions shutting a service down gracefully so I wonder if that is a documentation or an implementation bug?

Is there any update on this? Is this a bug, or a missing feature?

@kjackal can you confirm the remove hook runs after the services are stopped? So you can’t use it for this? If that’s the case I suggest you file a bug for this.

1 Like