nrepl: remove .nrepl-port on exit
Clean up the .nrepl-port file when the server stops — via defer on a clean unwind and SIGINT/SIGTERM handlers for Ctrl-C. A SIGKILL still can't be caught, so it may occasionally be left behind.
This commit is contained in:
parent
39049d6dba
commit
becc94431c
1 changed files with 7 additions and 1 deletions
|
|
@ -300,11 +300,17 @@
|
||||||
(eval-string ctx (string "(jolt.nrepl/start-server! {:host \"" host "\" :port " port "})"))
|
(eval-string ctx (string "(jolt.nrepl/start-server! {:host \"" host "\" :port " port "})"))
|
||||||
# Editors auto-discover the port from this file (nREPL convention).
|
# Editors auto-discover the port from this file (nREPL convention).
|
||||||
(spit ".nrepl-port" (string port))
|
(spit ".nrepl-port" (string port))
|
||||||
|
# Remove .nrepl-port on exit — on a clean unwind (defer) and on Ctrl-C/SIGTERM
|
||||||
|
# (signal handlers). A hard SIGKILL can't be caught, so it may still be left.
|
||||||
|
(def cleanup (fn [&] (protect (os/rm ".nrepl-port"))))
|
||||||
|
(os/sigaction :int (fn [&] (cleanup) (os/exit 0)) true)
|
||||||
|
(os/sigaction :term (fn [&] (cleanup) (os/exit 0)) true)
|
||||||
(print "Jolt nREPL server started on " host ":" port)
|
(print "Jolt nREPL server started on " host ":" port)
|
||||||
(print "Wrote .nrepl-port — connect your editor; Ctrl-C to stop.")
|
(print "Wrote .nrepl-port — connect your editor; Ctrl-C to stop.")
|
||||||
(flush)
|
(flush)
|
||||||
# Keep the main fiber alive so the event loop serves connections.
|
# Keep the main fiber alive so the event loop serves connections.
|
||||||
(forever (ev/sleep 60)))
|
(defer (cleanup)
|
||||||
|
(forever (ev/sleep 60))))
|
||||||
|
|
||||||
(defn- print-version []
|
(defn- print-version []
|
||||||
(print "jolt v" jolt-version))
|
(print "jolt v" jolt-version))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue