Github user Parth-Brahmbhatt commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/143#discussion_r13833622
--- Diff: storm-core/src/clj/backtype/storm/util.clj ---
@@ -388,13 +388,51 @@
(catch IOException e
(log-message "Could not extract " dir " from " jarpath))))
-(defn ensure-process-killed! [pid]
+(defn sleep-secs [secs]
+ (when (pos? secs)
+ (Time/sleep (* (long secs) 1000))))
+
+(defn sleep-until-secs [target-secs]
+ (Time/sleepUntil (* (long target-secs) 1000)))
+
+(def ^:const sig-kill 9)
+
+(def ^:const sig-term 15)
+
+(defn send-signal-to-process
+ [pid signum]
+ (try-cause
+ (exec-command! (str (if on-windows?
+ (if (== signum sig-kill) "taskkill /f /pid "
"taskkill /pid ")
+ (str "kill -" signum " "))
+ pid))
+ (catch ExecuteException e
+ (log-message "Error when trying to kill " pid ". Process is probably
already dead."))))
+
+(defn force-kill-process
+ [pid]
+ (send-signal-to-process pid sig-kill))
+
+(defn kill-process-with-sig-term
+ [pid]
+ (send-signal-to-process pid sig-term))
+
+(defn ensure-process-killed!
+ [pid]
;; TODO: should probably do a ps ax of some sort to make sure it was
killed
(try-cause
- (exec-command! (str (if on-windows? "taskkill /f /pid " "kill -9 ")
pid))
+ (kill-process-with-sig-term pid)
(catch ExecuteException e
(log-message "Error when trying to kill " pid ". Process is probably
already dead."))))
+(defn add-shutdown-hook-with-force-kill-in-1-sec
--- End diff --
You are right, I want to avoid a model where people have to call
(.addShutdownHook blah blah) and then remember to call
(add-shutdown-hook-with-force-kill-in-1-sec).
How about adding the use function and the actual forcing function as two
seperate shutdown hook threads?
(defn add-shutdown-hook-with-force-kill-in-1-sec
[func]
(.addShutdownHook (Runtime/getRuntime) (Thread. #(func)))
(.addShutdownHook (Runtime/getRuntime) (Thread. #((sleep-secs 1)
(.halt
(RunTime/getRunTime) 20)))))
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---