microservice-boilerplate icon indicating copy to clipboard operation
microservice-boilerplate copied to clipboard

Adds Gracefully Server Stop

Open rafaeldelboni opened this issue 4 years ago • 2 comments

Adds graceful stop

(defn -main
  "The entry-point for 'gen-class'"
  [& _args]
  (start-system! (build-system-map))
  ; Graceful shutdown
  (.addShutdownHook (Runtime/getRuntime)
                    (Thread. ^Runnable stop-system!)))

CC @lucascebertin

rafaeldelboni avatar Jul 24 '21 18:07 rafaeldelboni

Maybe follow something like this: https://gist.github.com/mourjo/ff04b46070c54e37b63a19d8957c3fcd#file-ordered-shutdown-clj

rafaeldelboni avatar Jul 24 '21 19:07 rafaeldelboni

The event addShutdownHook needs to be placed before (start-system! (build-system-map)). Without this small fix, signaling are not handled properly because of the control flow blocked by the webserver.

(defn -main
  "The entry-point for 'gen-class'"
  [& _args]
  ; Graceful shutdown
  (.addShutdownHook (Runtime/getRuntime) (Thread. ^Runnable stop-system!))
  (start-system! (build-system-map)))

lucascebertin avatar Jul 25 '21 15:07 lucascebertin