It's not quite the same as a service disposal method, but what I ended up doing is registering a Spring Bean with a shutdown method that gets called when the app is stopped.
First, create a bean class, like grails-app/utils/MyShutdownBean.groovy
that looks like the following (there's nothing sacred about the class name or the method name, use whatever you want):
class MyShutdownBean {
public void cleanup() {
// Do cleanup stuff
}
}
Then register the bean in grails-app/conf/spring/resources.groovy
like this:
beans = {
myShutdownHook(MyShutdownBean) { bean ->
bean.destroyMethod='cleanup'
}
}
If you want to only do the cleanup in production, you can register it like this instead:
beans = {
if (!grails.util.GrailsUtil.isDevelopmentEnv()) {
myShutdownHook(MyShutdownBean) { bean ->
bean.destroyMethod='cleanup'
}
}
}