Search code examples
clojurering

ring destroy function not called on ./bin/jetty.sh stop?


I have a ring project with the following configuration

:ring {:port 3000
       :handler myservice.core/standalone-app
       :init myservice.core/init!
       :destroy myservice.core/destroy!}

These functions are simple, they just log. They may do more someday.

(defn init! [] (log/info "init!"))

(defn destroy! [] (log/info "destroy!"))

I build this kid with the uberwar thing. lein ring uberwar myservice.war

The jetty log shows the init! logging on startup, but the destroy! logging is nowhere to be seen. Is destroy even being called? How can I tell?

The full project is at https://github.com/robertkuhar/myservice


Solution

  • It turns out I needed to configure the logging framework. It seems strange in the absence of logging configuration allows init! to log to stdout, but destroy! goes nowhere.

    I added logback to my project.clj as a dependency and gin'ed up a skeleton logback.xml config file and, viola!

    2015-12-23 11:42:53.192:INFO:oejs.Server:jetty-8.1.16.v20140903
    2015-12-23 11:42:53.208:INFO:oejdp.ScanningAppProvider:Deployment monitor /Users/robert.kuhar/work/jetty-distribution-8.1.16.v20140903/webapps at interval 1
    ...
    2015-12-23 11:42:53.598:INFO:oejd.DeploymentManager:Deployable added: /Users/robert.kuhar/work/jetty-distribution-8.1.16.v20140903/webapps/myservice.war
    2015-12-23 11:42:53.600:INFO:oejw.WebInfConfiguration:Extract jar:file:/Users/robert.kuhar/work/jetty-distribution-8.1.16.v20140903/webapps/myservice.war!/ to /private/var/folders/1g/fnytl2x93sx6hp2f1rsf4h1r5xtqv_/T/jetty-0.0.0.0-8080-myservice.war-_myservice-any-/webapp
    2015-12-23T11:42:58.851 INFO m.core - app
    2015-12-23T11:42:58.856 INFO m.core - standalone-app
    println init!
    2015-12-23T11:42:58.857 INFO m.core - init!
    ...
    2015-12-23 11:42:59.146:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
    ...
    2015-12-23 11:45:48.432:INFO:oejs.Server:Graceful shutdown SelectChannelConnector@0.0.0.0:8080
    ...
    2015-12-23 11:45:48.434:INFO:oejs.Server:Graceful shutdown o.e.j.w.WebAppContext{/myservice,file:/private/var/folders/1g/fnytl2x93sx6hp2f1rsf4h1r5xtqv_/T/jetty-0.0.0.0-8080-myservice.war-_myservice-any-/webapp/},/Users/robert.kuhar/work/jetty-distribution-8.1.16.v20140903/webapps/myservice.war
    println destroy!
    2015-12-23T11:45:49.553 INFO m.core - destroy!
    ...
    2015-12-23 11:45:49.553:INFO:oejsh.ContextHandler:stopped o.e.j.w.WebAppContext{/myservice,file:/private/var/folders/1g/fnytl2x93sx6hp2f1rsf4h1r5xtqv_/T/jetty-0.0.0.0-8080-myservice.war-_myservice-any-/webapp/},/Users/robert.kuhar/work/jetty-distribution-8.1.16.v20140903/webapps/myservice.war
    ...